<Connections>
<Connection ID = "1" Source="1:0" Sink="4:0"/>
<Connection ID = "2" Source="2:0" Sink="4:1"/>
<Connection ID = "3" Source="2:0" Sink="5:0"/>
<Connection ID = "4" Source="3:0" Sink="5:1"/>
<Connection ID = "5" Source="4:0" Sink="6:0"/>
<Connection ID = "6" Source="5:0" Sink="7:0"/>
</Connections>
When I need to get info from the previous XML code, Python's lxml can be used as follows.
def getNodeList(self):
connection = self.doc.find('Connections')
cons = connection.find('Connection')
for con in cons.iter():
con.get("ID") # get attribute
...
Based on dtb's answer, I could get what I needed.
using System;
using System.Xml;
using System.Xml.Linq;
namespace HIR {
class Dummy {
static void Main(String[] argv) {
XDocument doc = XDocument.Load("test2.xml");
var connection = doc.Descendants("Connections"); // .First();
var cons = connection.Elements("Connection");
foreach (var con in cons)
{
var id = (string)con.Attribute("ID");
Console.WriteLine(id);
}
}
}
}
I had to remove the 'First()' to avoid compiler error. With mono I could run the following to get the binary.
dmcs /r:System.Xml.Linq main.cs
You want to use LINQ-to-XML:
void GetNodeList()
{
var connection = this.doc.Descendants("Connections").First();
var cons = connection.Elements("Connection");
foreach (var con in cons)
{
var id = (string)con.Attribute("ID");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With