|
-
Mar 30th, 2004, 06:32 AM
#1
Thread Starter
Hyperactive Member
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
Last edited by Sgt-Peppa; Mar 30th, 2004 at 06:42 AM.
Keep Smiling - even if its hard 
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
-
Apr 1st, 2004, 10:26 AM
#2
Frenzied Member
try something like this
VB Code:
Function GetAttributeNames(oReader As XmlTextReader) As String
Dim sbAttributes As New StringBuilder
Do While (oReader.MoveToNextAttribute())
sbAttributes.Append(oReader.Name + " = " + oReader.Value + ",")
Loop
Return sbAttributes.ToString()
End Function
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Apr 2nd, 2004, 06:33 AM
#3
Thread Starter
Hyperactive Member
I finally ended up doing it all in loops, since this is just for a showcase, that quick hack was alright.
But still dont understand why it didnt work,.....
Thanx all,
Stephan
Keep Smiling - even if its hard 
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|