【问题标题】:how can I read this XML Document?我怎样才能阅读这个 XML 文档?
【发布时间】:2011-10-22 18:32:04
【问题描述】:

我还是个编程新手,我想阅读 XML 文档。它看起来像这样的示例代码:

<?xml version="1.0" encoding="utf-8"?>
<Etapa nombre="EnemigosTest" paredH="30" paredV="40">
  <Personaje vida="90" posX="24" posY="10">Cuberin</Personaje>
  <Items>
    <Item tipo="vida" maxApariciones="0" duracion="none" />
    <Item tipo="velocidad" maxApariciones="0" duracion="none" />
  </Items>
  <Plataformas>
    <Plataforma tipo="normal" posX="0" posY="36" ancho="1" duracion="none" />
    <Plataforma tipo="normal" posX="1" posY="36" ancho="1" duracion="none" />
  </Plataformas>
</Etapa>

另外,有没有办法知道文档中有多少节点/属性/元素?

【问题讨论】:

标签: xml xmldocument xmlreader


【解决方案1】:
    XDocument xDocument = XDocument.Load(string URI);
    Debug.WriteLine(xDocument.Elements().Count().ToString()); 

    foreach (XElement xl in xDocument.Elements())
    {
        Debug.WriteLine(xl.Count().ToString());
        foreach (XAttribute xa in xl.Attributes())
        {
            Debug.WriteLine(xa.ToString());
        }
    }

【讨论】:

    猜你喜欢
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 2015-04-06
    • 1970-01-01
    • 2019-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多