Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8250161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:47:39+00:00 2026-06-07T23:47:39+00:00

Hi I’m having trouble extracting data from this XML document. <messages messageCount=6> <message messageID=9999

  • 0

Hi I’m having trouble extracting data from this XML document.

  <messages messageCount="6">
  <message messageID="9999" orderNumber="1234" model="TESTMODEL" val="490" status="8" timestamp="2012-07-12 13:12:50Z">
  <attributes>
  <attribute name="ATT1" value="1234" /> 
  <attribute name="ATT2" value="5678" /> 
  </attributes>
  </message>
  </messages>

I need to recursively loop through each message and get the values of the message node. I then need to loop through the attributes and get the value of the attribute nodes if the status is a certain value. I’m having a bit of trouble. So far I have this

        Dim strStream As New MemoryStream(System.Text.Encoding.UTF8.GetBytes(strMessage))

        Dim XmlDoc As XmlDocument = New XmlDocument

        XmlDoc.Load(strStream)


        Dim nlNodeList As XmlNodeList = XmlDoc.SelectNodes("//messages/message")
        Dim a As XmlAttribute

        For Each nNode As XmlNode In nlNodeList
            Dim strmessageID As String = String.Empty
            For Each a In nNode.Attributes
                If a.Name = "messageID" Then
                    strmessageID = a.Value
                End If
            Next
            For Each nChildNode As XmlNode In nNode.ChildNodes
                For Each b In nChildNode.ChildNodes
                    For Each a In b.Attributes
                        If a.Name = "ATT1" Then

                        End If
                    Next
                Next
            Next
        Next

but i’m having trouble getting the attribute values. I’m sure there must be a cleaner way of doing this too. I was previously using Datasets and was fine until I tried to get to the attributes values

    For Each dr As DataRow In dsmyDS.Tables("message").Rows
        Dim strMessageID As String = dr.Item("messageid").ToString
        Select Case CStr(dr.Item("model").ToString)
            Case "TESTMODEL"
                Select Case dr.Item("status").ToString
                    Case "8"
                        Dim strval As String = dr.Item("val").ToString
                        'Don't know how to get at the attributes node list once I'm here
                    Case Else

                End Select
            Case Else

        End Select
    Next

It would great if someone could tell me what I’m doing wrong. Which is the best method to use? XMLDocument or a Dataset? Is there an easier way then my longwinded method?

Any help would be great thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:47:40+00:00Added an answer on June 7, 2026 at 11:47 pm

    You should try LINQ-XML Import the System.Data.Xml.

     Dim doc As XDocument = XDocument.Load(file)
    'Or
    'Dim doc As XDocument = XDocument.Parse(strMessage)
     Dim Result = doc.Root.Descendants("message")
                          .Where(Function(p)
                                    Return p.Attribute("status").Value = "8"
                                 End Function)
     For Each ele In Result
         MsgBox(ele.Attribute("messageID").Value)
         MsgBox(ele.Element("attributes").Element("attribute").Attribute("name").Value)
    
         'List children of attributes tag
         For Each v In ele.Element("attributes").Elements()
              MsgBox(v.Attribute("name").Value & " " & v.Attribute("value").Value)
         Next
     Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.