有一个XML文件,其中有一段是这样的 <Device
Facility="SMIC-F8"
Technology="1118C014.N7NOW"
WaferSize="300"
EdgeExclusion="3000"
NotchExclusionWidth="12500"
NotchExclusionHeight="3500"
WaferConfigFile="SMIC-F8_1118C014.N7NOW_F781537B_20111104000000_wfcfg.xml"
CreateDate="20111104000000"
Orientation="270"
ReticleOrientation="0"
/>
用IE打开看各个属性是不换行的,但是用UE等编辑器打开是换行的
请问这个该如何实现?
谢谢!
PS. 开发环境:VS2010
Facility="SMIC-F8"
Technology="1118C014.N7NOW"
WaferSize="300"
EdgeExclusion="3000"
NotchExclusionWidth="12500"
NotchExclusionHeight="3500"
WaferConfigFile="SMIC-F8_1118C014.N7NOW_F781537B_20111104000000_wfcfg.xml"
CreateDate="20111104000000"
Orientation="270"
ReticleOrientation="0"
/>
用IE打开看各个属性是不换行的,但是用UE等编辑器打开是换行的
请问这个该如何实现?
谢谢!
PS. 开发环境:VS2010
//生成节点属性文件
Properties properties = new Properties();
String path = ServletActionContext.getServletContext().getRealPath("/")+"WEB-INF\\classes\\qpe.properties";
java.io.FileInputStream fin=new java.io.FileInputStream(path);
properties.load(fin);//生成了水库对象实体列表
ArrayList RESList = getRESInfo(rvid);//生成新的XML文档对象
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
Element root = doc.createElement("ROOT");//开始组织XML文件
XMLUtil util = XMLUtil.getInstance(doc);//生成PQE节点
String elementAttribute = properties.getProperty("QPE");
Element QPEElement = util.createElement(elementAttribute);
root.appendChild(QPEElement);Element e = null;
//获得XML文件的任务部分
e = getTaskInfoElement(RESList,properties,doc,st,etm,QPEType);
QPEElement.appendChild(e);//获得XML文件的参数部分
e = getCondINFOElement(RESList,properties,doc,st,et);
QPEElement.appendChild(e);//获得XML文件的数据部分
e = getQPEInfoElement(RESList,properties,doc,rvid,st,et);
QPEElement.appendChild(e);if(root!=null){//root节点存在开始生成文件
doc.appendChild(root);
TransformerFactory tff=TransformerFactory.newInstance();
Transformer tf=tff.newTransformer();
tf.setOutputProperty("encoding","gb2312");
DOMSource source=new DOMSource(doc);
StreamResult result=new StreamResult(new File(filePath));
tf.transform(source,result);
}
}catch(Exception e){
e.printStackTrace();
return false;
}
就像我示例中显示的那样
不要使用xmlwriter,因为这个只有两种排版,一是无空格无换行,紧缩模式,另外一种是缩进模式,但对Attribute不会有换行。
如果要实现你的要求,那Attribute之间需要换行,那只能自己输出文本了。
xmldoc.CreateTextNode("\r\n");试了,没用
new XDeclaration("1.0", "utf-8", "yes"),
new XElement("Root",
new XAttribute("attr1", "value"),
new XAttribute("attr2", "value")
)
);
Console.WriteLine(doc); using (StreamWriter sw = new StreamWriter(@"D:\test.xml")) {
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = " ";
settings.NewLineOnAttributes = true;
XmlWriter xmlWriter = XmlWriter.Create(sw, settings);
doc.Save(xmlWriter);
xmlWriter.Close();
}
settings.Indent = true;
settings.IndentChars = " ";
settings.NewLineOnAttributes = true;
跟读取这个xml的软件有关·