How to select the attributes?
Hey all, I have an xml File and need to read the attributes.
Heres my xml File:
Code:
<myRespRoot xmlns="http://myDatabaseAnswer/sql">
<Schema name="Schema1" xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes">
<ElementType name="dbo.DataSets" content="empty" model="closed">
<AttributeType name="IDNumber" dt:type="string" />
<AttributeType name="ForeName" dt:type="string" />
<AttributeType name="SureName" dt:type="string" />
<AttributeType name="Street" dt:type="string" />
<AttributeType name="PostalCode" dt:type="string" />
<AttributeType name="City" dt:type="string" />
<AttributeType name="DateOfBirth" dt:type="string" />
<AttributeType name="Sex" dt:type="string" />
<AttributeType name="Nationality" dt:type="string" />
<AttributeType name="MothersBirthLastName" dt:type="string" />
<attribute type="IDNumber" />
<attribute type="ForeName" />
<attribute type="SureName" />
<attribute type="Street" />
<attribute type="PostalCode" />
<attribute type="City" />
<attribute type="DateOfBirth" />
<attribute type="Sex" />
<attribute type="Nationality" />
<attribute type="MothersBirthLastName" />
</ElementType>
</Schema>
<dbo.DataSets xmlns="x-schema:#Schema1" IDNumber="P4711" ForeName="myName" SureName="myLastName" Street="myStreet" PostalCode="12345" City="myCity" DateOfBirth="01.01.1901" Sex="male" Nationality="German" MothersBirthLastName="myMothersBirthLastName" />
</myRespRoot>
Ok, what I am trying to do is to read the attributes IDNumber, Forename......
This is usually no problem but this time everytime I try to use this code:
Code:
XmlDocument myDoc = new XmlDocument();
myDoc.LoadXml(textBox1.Text);
textBox2.Text=myDoc.DocumentElement.SelectSingleNode("//dbo.PSI_DataSets").Attributes.GetNamedItem("IDNumber").InnerText.ToString();
I get the error saying Object reference not set to an instance of an object.
This even happens when I just try to get the SingleNode.
Anyone knows how to get to the attributes values?
Thanks,
Stephan