I have a large xml file with following structure.This is a snippet which contains many <xn:TestElement>
nodes.
<?xml version="1.0" encoding="utf-8" ?>
<testDataFile
xmlns="http://www.3gpp.org/ftp/specs/archive/32_series/32.615#configData"
xmlns:xn="http://www.3gpp.org/ftp/specs/archive/32_series/32.625#genericNrm" xmlns:in="http://www.3gpp.org/ftp/specs/archive/32_series/32.695#inventoryNrm">
<fileHeader fileFormatVersion="32.615 V6.3" vendorName="TestVendor"/>
<configData dnPrefix="">
<xn:SubNetwork id="ONRM_ROOT_MO">
<xn:SubNetwork id="RNC425">
<xn:TestElement id="DA_Test_place0">
<xn:attributes>
<xn:userLabel>DA_Test_place0</xn:userLabel>
</xn:attributes>
<in:InventoryUnit id="n/a">
<in:attributes>
<in:manufacturerData>ProductName=Non-subrack HW,SlotCount=0</in:manufacturerData>
</in:attributes>
<in:InventoryUnit id="0">
<in:attributes>
<in:vendorUnitTypeNumber>KRC11876/1_R4A</in:vendorUnitTypeNumber>
<in:manufacturerData>ProductName=RUS 02 B8</in:manufacturerData>
</in:attributes>
</in:InventoryUnit>
<in:InventoryUnit id="0">
<in:attributes>
<in:vendorUnitTypeNumber>test/1_R4A</in:vendorUnitTypeNumber>
</in:attributes>
</in:InventoryUnit>
</in:InventoryUnit>
<in:InventoryUnit id="n/a">
<in:attributes>
<in:manufacturerData>ProductName=Virtual subrack,SlotCount=2</in:manufacturerData>
</in:attributes>
<in:InventoryUnit id="1">
<in:attributes>
<in:vendorUnitTypeNumber>KDU127174/4_R2D/A</in:vendorUnitTypeNumber>
</in:attributes>
</in:InventoryUnit>
<in:InventoryUnit id="1">
<in:attributes>
<in:vendorUnitTypeNumber>KDU127174/4_R2D/B</in:vendorUnitTypeNumber>
<in:manufacturerData>ProductName=RUS 02 B7</in:manufacturerData>
</in:attributes>
</in:InventoryUnit>
</in:InventoryUnit>
</xn:TestElement>
<xn:TestElement id="DA_Test_place1">
</xn:TestElement>
</xn:SubNetwork>
</xn:SubNetwork>
</configData>
</testDataFile>
Now I want to process this xml get information like:
testelementname slotdata inventory unit number
------------------------------------------------------------------------------
DA_Test_place0 ProductName=Non-subrack HW,SlotCount=0 KRC11876/1_R4A
DA_Test_place0 ProductName=Non-subrack HW,SlotCount=0 test/1_R4A
DA_Test_place0 ProductName=Virtual subrack,SlotCount=2 KDU127174/4_R2D/A
DA_Test_place0 ProductName=Virtual subrack,SlotCount=2 KDU127174/4_R2D/B
How can I process this xml file and get information either in datatable or C# classes. I wrote the following code, but it got stuck with the hierarchy of xml
while (reader.Read())
{
if (reader.Name != "xn:TestElement")
{
reader.ReadToFollowing("xn:TestElement");
}
while (reader.NodeType == XmlNodeType.Element && reader.LocalName == "TestElement")
{
XElement elements = (XElement)XElement.ReadFrom(reader);
testelemenname = reader.GetAttribute("id");
slotdata = GetInventoryValue(elements, "manufacturerData");
invenotry unit number = GetInventoryValue(elements, "vendorUnitTypeNumber");
}
}
private static string GetInventoryValue(XElement pin, string input)
{
XElement manufacturerData = pin.Descendants().Where(a => a.Name.LocalName == input).FirstOrDefault();
if (manufacturerData != null)
{
return (string)manufacturerData;
}
}
EDIT
Heirarchy of XML changed a bit and added two level 'SubNetwork
' node and one more node 'configData'and
namespaces also changed,now i am not getting the result