New topic: 

XML GetAttribute (noob) question - (Resolved)

<http://forums.realsoftware.com/viewtopic.php?t=47705>

         Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic          Author  
Message        ChickenScratch          Post subject: XML GetAttribute (noob) 
question - (Resolved)Posted: Thu Apr 25, 2013 2:29 pm                         
Joined: Fri Feb 15, 2008 5:14 pm
Posts: 221                I have not played much with parsing XML with RB but 
so far, things seemed pretty easy.  However, I have come across a problem that 
I hope someone here can help me with.  Here is a sample code that I am testing:

Dim xdata As String = "<dwml><data attr=""first_name"">User</data><data 
attr=""last_name"">One</data></dwml>"
Dim doc as new XmlDocument
Dim xnl As XmlNodeList

doc.LoadXml(xdata)

xnl = doc.DocumentElement.Xql("//dwml/data")

// Show the value of the first "data" node (in this test case, should be "User")
msgbox xnl.item(0).firstchild.value


Getting the value is pretty straight forward.  However, how would I go about 
getting "first_name" from attr="first_name"?  I'm hoping to avoid 
<node>.tostring and then parse it out or use regular expressions to get 
whatever it is between the quotes.  With just two sibling nodes, it's not a 
problem to search for "first_name", but what happens when you have hundreds of 
different attr="?????"?

I thought <node>.GetAttribute("attr") would have done it, but it doesn't.  Any 
insights would be appreciated.

Thanks.     

    Last edited by ChickenScratch on Thu Apr 25, 2013 5:53 pm, edited 1 time in 
total.   
                             Top                ChickenScratch          Post 
subject: Re: XML GetAttribute (noob) questionPosted: Thu Apr 25, 2013 2:40 pm   
                      
Joined: Fri Feb 15, 2008 5:14 pm
Posts: 221                NVM, duh moment.  I was calling 
xnl.item(0).firstchild.GetAttribute, which is the wrong place.  Calling 
xnl.item(0).GetAttribute did the trick.

ChickenScratch wrote:I have not played much with parsing XML with RB but so 
far, things seemed pretty easy.  However, I have come across a problem that I 
hope someone here can help me with.  Here is a sample code that I am testing:

Dim xdata As String = "<dwml><data attr=""first_name"">User</data><data 
attr=""last_name"">One</data></dwml>"
Dim doc as new XmlDocument
Dim xnl As XmlNodeList

doc.LoadXml(xdata)

xnl = doc.DocumentElement.Xql("//dwml/data")

// Show the value of the first "data" node (in this test case, should be "User")
msgbox xnl.item(0).firstchild.value


Getting the value is pretty straight forward.  However, how would I go about 
getting "first_name" from attr="first_name"?  I'm hoping to avoid 
<node>.tostring and then parse it out or use regular expressions to get 
whatever it is between the quotes.  With just two sibling nodes, it's not a 
problem to search for "first_name", but what happens when you have hundreds of 
different attr="?????"?

I thought <node>.GetAttribute("attr") would have done it, but it doesn't.  Any 
insights would be appreciated.

Thanks.   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to