I'm trying to read an XML file and parse its content, but I'm having trouble extracting parameters from the file.
The XML file I'm trying to parse looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <root> <register_map> <Register ID="1" Index="0x100000" DataType="0x0007" ObjectType="0x07" Name="Device Type"/> <Register ID="2" Index="0x100100" DataType="0x0005" ObjectType="0x07" Name="Error Register"/> </register_map> </root> My code so far looks like this
namespace Test_XML { class Program { struct RegisterEntry { public UInt32 index; public UInt16 dataType; public UInt16 objectType; public string name; }; static void Main(string[] args) { XDocument doc = XDocument.Load("registers.xml"); var registers = doc.Descendants("register_map"); foreach (var register in registers) { // Fill up a list of RegisterEntrys with contents of XML } Console.ReadLine(); } } } How can I extract the parameters from "registers" and place them in a RegisterEntry object?
No comments:
Post a Comment