Results 1 to 6 of 6

Thread: get xml attribute

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    470

    get xml attribute

    Hello,

    I have a xml node which is

    Code:
    <Tender TenderID="1" TenderGroup="1" TenderDescription="Cash" AmountEntered="9.99" />
    <Tender TenderID="10" TenderGroup="3" TenderDescription="Check" AmountEntered="0.00" />
    <Tender TenderID="22" TenderGroup="11" TenderDescription="Travelers Check" AmountEntered="0.00" />
    Now I want to get TenderDescription="Cash" AmountEntered="9.99"(Strings)

    How to?

    Thanks

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: get xml attribute

    try this:

    vb Code:
    1. Dim xmlDoc As New Xml.XmlDocument
    2. xmlDoc.LoadXml("<root><Tender TenderID=""1"" TenderGroup=""1"" TenderDescription=""Cash"" AmountEntered=""9.99"" /><Tender TenderID=""10"" TenderGroup=""3"" TenderDescription=""Check"" AmountEntered=""0.00"" /><Tender TenderID=""22"" TenderGroup=""11"" TenderDescription=""Travelers Check"" AmountEntered=""0.00"" /></root>")
    3. For Each node As XmlNode In xmlDoc.SelectNodes("root/Tender")
    4.     Dim TenderDescription As String = node.Attributes("TenderDescription").Value
    5.     Dim AmountEntered As String = node.Attributes("AmountEntered").Value
    6.     MsgBox(TenderDescription & vbcrlf & AmountEntered)
    7. Next
    Last edited by .paul.; Dec 17th, 2008 at 11:08 AM.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    470

    Re: get xml attribute

    <REASON_CODES>
    <REASON ID="5" Description="Cheque Reason" />
    </REASON_CODES>

    How to get 5?

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: get xml attribute

    vb Code:
    1. Dim xmlDoc As New Xml.XmlDocument
    2. xmlDoc.LoadXml("<REASON_CODES><REASON ID=""5"" Description=""Cheque Reason"" /></REASON_CODES>")
    3. Dim id As Integer = xmlDoc.SelectSingleNode("REASON_CODES/REASON").Attributes("ID").Value
    4. MsgBox(id)

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    470

    Re: get xml attribute

    A basic question.
    Code:
    <REASON_CODES>
      <REASON ID="555" Description="Test" /> 
     </REASON_CODES>
    Is it same as


    Code:
    <REASON_CODES REASON ID="555" Description="Test">
     </REASON_CODES>

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    470

    Re: get xml attribute

    Forget it.

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