2011-10-22 114 views
0

我在編程上還是個新手,我想讀一個XML文檔。它看起來是這樣的示例代碼:我如何閱讀這個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> 

此外,有沒有一個知道有多少個節點/ atributtes /元素在文檔中的方法?

+1

此外,見http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts –

+2

什麼平臺/編程語言你想用嗎? –

回答

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()); 
     } 
    }