Page 1 of 1

Structured List and ExtractXMLList()

Posted: Wed Oct 09, 2024 3:46 pm
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 ?

Re: Structured List and ExtractXMLList()

Posted: Wed Oct 09, 2024 4:30 pm
by mk-soft
Internal specifications. It must be <element>

Re: Structured List and ExtractXMLList()

Posted: Wed Oct 09, 2024 4:33 pm
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.

Re: Structured List and ExtractXMLList()

Posted: Thu Oct 10, 2024 7:06 am
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 ?