Structured List and ExtractXMLList()

Just starting out? Need help? Post your questions and find answers here.
tatanas
Enthusiast
Enthusiast
Posts: 260
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Structured List and ExtractXMLList()

Post by tatanas »

Hi,

Here is a working code :

Code: Select all

Structure Position
	x.l
	y.l
EndStructure
NewList Positions.Position()

Xml$ = "<report>" +
      	 "<element>" +
       			"<x>100</x>" +
       			"<y>200</y>" +
       	  "</element>" +
      	  "<element>" +
       			"<x>200</x>" +
       			"<y>400</y>" +
       	  "</element>" +
      "</report>"

If ParseXML(0, Xml$) And XMLStatus(0) = #PB_XML_Success
	ExtractXMLList(MainXMLNode(0), Positions(), #PB_XML_NoCase)

	Debug ListSize(Positions())
	
	ForEach Positions()
		Debug Positions()\x
		Debug Positions()\y
	Next
Else
	Debug XMLError(0)
EndIf
If you replace the "<element>" node by another name, let's say "elem", it doesn't work anymore ???

Code: Select all

Structure Position
	x.l
	y.l
EndStructure
NewList Positions.Position()

Xml$ = "<report>" +
      	 "<elem>" +
       			"<x>100</x>" +
       			"<y>200</y>" +
       	  "</elem>" +
      	  "<elem>" +
       			"<x>200</x>" +
       			"<y>400</y>" +
       	  "</elem>" +
      "</report>"

If ParseXML(0, Xml$) And XMLStatus(0) = #PB_XML_Success
	ExtractXMLList(MainXMLNode(0), Positions(), #PB_XML_NoCase)

	Debug ListSize(Positions())
	
	ForEach Positions()
		Debug Positions()\x
		Debug Positions()\y
	Next
Else
	Debug XMLError(0)
EndIf
What did I missed ?
Windows 10 Pro x64
PureBasic 6.20 x64
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Structured List and ExtractXMLList()

Post by mk-soft »

Internal specifications. It must be <element>
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
HeX0R
Addict
Addict
Posts: 1219
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: Structured List and ExtractXMLList()

Post by HeX0R »

tatanas wrote: Wed Oct 09, 2024 3:46 pmWhat did I missed ?
You probably missed to look into the help file of ExtractXMLList()?
help file wrote:The XML nodes must have the form described in the InsertXMLList() function. Nodes with different names are ignored by the extraction.
tatanas
Enthusiast
Enthusiast
Posts: 260
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Re: Structured List and ExtractXMLList()

Post by tatanas »

I read the documentation but I didn't understand that part. Having played a lot with the json library, I thought it worked in a similar way. So if I understand correctly, to retrieve data from an xml file with ExtractXMLList(), I need to rename the main node to "list" and the children to "element" ?
And whatabout the nested elements ?
Windows 10 Pro x64
PureBasic 6.20 x64
Post Reply