Getting XML attributes into a structure?

Just starting out? Need help? Post your questions and find answers here.
Joubarbe
Enthusiast
Enthusiast
Posts: 552
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Getting XML attributes into a structure?

Post by Joubarbe »

Code: Select all

Structure Person
  Name$
  Age.l
EndStructure

Xml$ = ~"<Person><Name attribute=\"foo\">John Smith</Name><Age>42</Age></Person>"

If ParseXML(0, Xml$) And XMLStatus(0) = #PB_XML_Success
  Define P.Person
  ExtractXMLStructure(MainXMLNode(0), @P, Person)
  
  Debug P\Name$
  Debug P\Age
Else
  Debug XMLError(0)
EndIf 
I think I've read the whole doc, but didn't understand everything... Is there a way to extract attributes from a node, and not only its content? For instance, in the code above, the attribute "foo". The XML I'm working on has actually no content, but only a long list of nodes with attributes only. Things like this:

Code: Select all

<o t="18" s="6" x="5950000" y="0" z="-13510000" gid="1" gx="0" gy="1" gtid="0" a="-22528" b="9216" g="0"/>
And I would like to be able to parse that.
nsstudios
Enthusiast
Enthusiast
Posts: 274
Joined: Wed Aug 28, 2019 1:01 pm
Location: Serbia
Contact:

Re: Getting XML attributes into a structure?

Post by nsstudios »

Very confused about the same issue. in my case I want to extract an xml into a structure, but I can't seem to be able to handle attributes
benubi
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Mar 29, 2005 4:01 pm

Re: Getting XML attributes into a structure?

Post by benubi »

It fills the structure with XML child elements and not with attributes, sadly. It would be great if there was an option to extract the attributes instead of the child nodes, an additional flag or entirely separate functions.
nsstudios
Enthusiast
Enthusiast
Posts: 274
Joined: Wed Aug 28, 2019 1:01 pm
Location: Serbia
Contact:

Re: Getting XML attributes into a structure?

Post by nsstudios »

+1
Post Reply