I'm still new on programming and I want to read an XML Document. It looks something like this sample-code:
我还是编程新手,我想阅读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>
Also, is there a method to know how many nodes/atributtes/elements are in the document?
另外,有没有一种方法可以知道文档中有多少节点/属性/元素?
1 个解决方案
#1
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());
}
}
#1
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());
}
}