Page 1 of 1

ExtractXMLArray only extracts child elements with tag "element"

Posted: Sat Jan 08, 2022 4:45 pm
by Programie
ExtractXMLArray() allows us to extract XML elements into an array. Unfortunately, this function expects a specific XML tag name for the child elements.

If we take the following example from the ExtractXMLArray() documentation it will work fine:

Code: Select all

Xml$ = "<array><element>1</element><element>10</element><element>100</element></array>"

If ParseXML(0, Xml$) And XMLStatus(0) = #PB_XML_Success
  Dim MyArray(0) ; will be resized by the next call
  ExtractXMLArray(MainXMLNode(0), MyArray())

  For i = 0 To ArraySize(MyArray())
    Debug MyArray(i)
  Next i
Else
  Debug XMLError(0)
EndIf
But once we change the tag name "element" to something else, it won't work anymore as ExtractXMLArray() is only searching for elements with the tag name "element".

Therefore, we can't use ExtractXMLArray() for XML structures using a different tag name for it's array elements.

ExtractXMLElement() should provide an additional parameter allowing the developer to define the tag name to use for searching for the child element. Or even better: Simply use all direct child elements independently of the name.

Re: ExtractXMLArray only extracts child elements with tag "element"

Posted: Sat Jan 08, 2022 4:46 pm
by RSBasic
+1, I confirm this.