Results 1 to 3 of 3

Thread: How to select the attributes?

  1. #1

    Thread Starter
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476

    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

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    try something like this
    VB Code:
    1. Function GetAttributeNames(oReader As XmlTextReader) As String
    2.     Dim sbAttributes As New StringBuilder
    3.  
    4.     Do While (oReader.MoveToNextAttribute())
    5.         sbAttributes.Append(oReader.Name + " = " + oReader.Value + ",")
    6.     Loop
    7.  
    8.     Return sbAttributes.ToString()
    9. End Function
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  3. #3

    Thread Starter
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476
    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
  •  



Click Here to Expand Forum to Full Width