This is given XML:
<NewDataSet>
<Table>
<ProductCode>0120314</ProductCode>
<SpecificationItemName>USB</SpecificationItemName>
<SpecificationItemValues><Values xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Value>USB 2.0</Value></Values></SpecificationItemValues>
</Table>
<Table>
<ProductCode>0987046</ProductCode>
<SpecificationItemName>Other</SpecificationItemName>
<SpecificationItemValues><Values xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Value>1 x PCIe 2.0 x16</Value><Value>2 x PCIe 2.0 x1</Value></Values></SpecificationItemValues>
</Table>
</NewDataSet>
And this is my solution to read ProductCode, SpectificationItemName and complete value of SpecificationItemValues. Can you help me to read SpecificationItemValues by values (one by one, if more than one)? Thank you.
This is my code:
foreach (XmlNode nodeSpecification in xmlDokument.SelectSingleNode("//NewDataSet"))
{
if (nodeSpecification.Name == "Table")
{
foreach (XmlNode nodeElements in nodeSpecification)
{
if (nodeElements.Name == "ProductCode")
{
MessageBox.Show(nodeElements.InnerText);
}
if (nodeElements.Name == "SpecificationItemName")
{
MessageBox.Show(nodeElements.InnerText);
}
if (nodeElements.Name == "SpecificationItemValues")
{
MessageBox.Show(nodeElements.InnerText);
}
} //you were missing a closing } by the way
}
}