Page 1 of 1

XML and ?xml version How to

Posted: Sun Oct 03, 2021 4:48 pm
by loulou2522
How to put tha't instruct on the xml file in purebasic it is automaticly
<?xml version="1.0" encoding="UTF-8"?>
Thanks
P.S I use ExportXml and not composeXML

Re: XML and ?xml version

Posted: Sun Oct 03, 2021 5:23 pm
by Paul
Just add it yourself?

Code: Select all

  xml = CreateXML(#PB_Any) 
  mainNode = CreateXMLNode(RootXMLNode(xml), "Zoo") 
  
  ; Create first xml node (in main node)
  item = CreateXMLNode(mainNode, "Animal") 
  SetXMLAttribute(item, "id", "1") 
  SetXMLNodeText(item, "Elephant") 
  
  ; Create second xml node (in main node)
  item = CreateXMLNode(mainNode, "Animal") 
  SetXMLAttribute(item, "id", "2") 
  SetXMLNodeText(item, "Tiger") 
  
  ; Display the xml
  result$=~"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ComposeXML(xml)
  Debug result$
Of course if you are using ExportXML() then this won't help ;(
I thought maybe SetXMLEncoding() might add this info since the docs make me think it should do something but when I try and use this command the browser gives an error saying "spider_SetXMLEncoding" is not defined, so no idea.