I need a little help with reading some XML from a web service. I load the XML into an XML document like this.
XmlDocument doc = new XmlDocument();
doc.LoadXml(responseString);
And doc.InnerText shows the text of this node, and all its child nodes. That seems to be working, but its all bunched together. How Would I got about getting the individual elements like first_name or last_name.
I would have assumed something like
foreach (XmlNode node in doc.ChildNodes)
{
MessageBox.Show(node["first_name"].Value);
}
would work, but node["first_name"].Value gives me a null reference exception error.
The XML I'm working with looks like this:
<?xml version="1.0" encoding="utf-8"?>
<DataSet xmlns="https://www.example.com/">
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="client_id" type="xs:int" minOccurs="0" />
<xs:element name="first_name" type="xs:string" minOccurs="0" />
<xs:element name="last_name" type="xs:string" minOccurs="0" />
<xs:element name="home_phone" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<Table diffgr:id="Table1" msdata:rowOrder="0">
<client_id>1002</client_id>
<first_name>Sam</first_name>
<last_name>Spade</last_name>
<home_phone>5405555555</home_phone>
</Table>
</NewDataSet>
</diffgr:diffgram>
</DataSet>