本文介绍了使用C#创建Xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



i想要创建xml文件,但我无法获得相同的skelton。

我该如何解决?

和我的错误是什么?



原始Xml:

Hello,

i want to create xml file but i cant get same skelton.
How can i fix?
and whats my mistake?

Original Xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sx_xmlfile>
   <sx_header>
     <sxxml_vers>1.0</sxxml_vers>
     <sxcom_vers>8.0</sxcom_vers>
<sx_table>BOKA</sx_table>
<sx_cmd>H</sx_cmd>
<sx_id>00</sx_id>
  </sx_header>
  <sx_data>
<sx_r>STYP1WALO1</sx_r>
  </sx_data>
</sx_xmlfile>





我的c#代码是:



my c# code is:

XDocument doc = new XDocument(
               new XDeclaration("1.0", "UTF-8", "yes"),
               new XElement("sx_xmlfile",
                   new XElement("sx_header",
                       new XElement("sxxml_vers","1.0"),new XElement("sxcom_vers","8.0")
                      ,new XElement("sx_table","BOKA"),new XElement("sx_cmd","H"),new XElement("sx_id","00")))
                   );





我的代码xml提取:



My code xml extraction:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<sx_xmlfile>
  <sx_header>
    <sxxml_vers>1.0</sxxml_vers>
    <sxcom_vers>8.0</sxcom_vers>
  </sx_header>
  <sx_table>BOKA</sx_table>
  <sx_cmd>H</sx_cmd>
  <sx_id>00</sx_id>
</sx_xmlfile>





我尝试了什么:



查看一些来源并查看和示例



What I have tried:

looking some sources and looking and examples

推荐答案

<br />
    XElement sx_table= new XElement("sx_table","BOKA");<br />
    XElement sx_cmd= new XElement("sx_cmd","H");<br />
    XElement sx_id= new XElement("sx_id","00);<br />
<br />
    XElement sx_header= new XElement("sx_header",<br />
                              new XElement("sxxml_vers","1.0),<br />
                              new XElement("sxcom_vers","8.0"),<br />
                              sx_table,sx_cmd,sx_id<br />
                             );<br />
<br />
<br />
    XElement sx_r= new XElement("sx_r","STYP1WAL01");      <br />
    XElement sx_data = new XElement("sx_data",sx_r);<br />
<br />
    XDocument doc = new XDocument(<br />
                new XDeclaration("1.0", "UTF-8", "yes"),<br />
                new XElement("sx_xmlfile", sx_header, sx_data);<br />
<br />





是使用预先创建的元素和对应于< sx_header>和< sx_data>



The is created using the pre-created elements and corresponding to the <sx_header> and <sx_data>


这篇关于使用C#创建Xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 22:20