C#加载XML方式

//path:xml文件路径  SECSMessage:xml文件的根元素下的第一个子集元素

<SECSLibrary>

  <SECSMessage>

    <Description name="hello">

      hello

    </Description>

  </SECSMessage>

  <SECSMessage>

  </SECSMessage>

</SECSLibrary>

var xmlDocument = XDocument.Load(path).Root.Elements("SECSMessage");

foreach (var msg in xmlDocument)
{

  msg.Element("Description").Value;

  //同理,也可以获取相应的属性值

  msg.Attribute("name“).Value;

}

 

posted @ 2019-08-02 10:40  初次的告白  阅读(1337)  评论(0编辑  收藏  举报