C#写XML问题?
用C#写这种XML,其中有几个问题
1、GBK怎么写
2、怎么换行
3、结点的属性: <DataTrans DataTransType= "supplyCollect " DataTransId= "2 "> 中DataTransType= "supplyCollect " DataTransId= "2 "这部分怎么写
<?xml version= "1.0 " encoding= "GBK "?>
<!--说明-->
<Records DataType= "PowerPlant ">
<!--数据-->
<DataTrans DataTransType= "substation " DataTransId= "1 ">
<Data_1> 0 </Data_1>
<Data_2> 9 </Data_2>
</DataTrans>
<!--汇总数据-->
<DataTrans DataTransType= "supplyCollect " DataTransId= "2 ">
<Data_sum> 23.0 </Data_sum>
</DataTrans>
[解决办法]
XmlDocument xmldoc = new XmlDocument();
XmlProcessingInstruction _oProcIntr = xmldoc.CreateProcessingInstruction( "xml ", "version=\ "1.0\ " encoding=\ "GBK\ " ");
xmldoc.AppendChild(_oProcIntr);
XmlNode _oNode;
XmlAttribute _attr;
_oNode = xmldoc.CreateElement( "Records ");
_attr = xmldoc.CreateAttribute( "DataType ");
_attr.Value = "PowerPlant ";
_oNode.Attributes.Append(_attr );
XmlNode _oSubNode;
_oNode.AppendChild(xmldoc.CreateTextNode( "\n ")); '实现换行效果
_oSubNode = xmldoc.CreateElement( "DataTrans ");
_attr = xmldoc.CreateAttribute( "DataTransType ");
_attr.Value = "substation ";
_oSubNode.Attributes.Append(_attr);
_attr = xmldoc.CreateAttribute( "DataTransId ");
_attr.Value = "1 ";
_oSubNode.Attributes.Append(_attr);
_oNode.AppendChild(_oSubNode);
_oNode.AppendChild(xmldoc.CreateTextNode( "\n "));
xmldoc.AppendChild(_oNode);
Response.Write(xmldoc.OuterXml);