Page 1 of 1

XMLToString

Posted: Fri Apr 11, 2014 10:07 pm
by eddy
- convert XML to string
- I don't know how to handle encoding

Code: Select all

Procedure.s XMLToString(XML)  
  Protected mainNode=MainXMLNode(xml)
  If mainNode 
    !return v_mainNode.outerHTML;
  EndIf   
EndProcedure  


CompilerIf #PB_Compiler_IsMainFile  

; Create xml tree
xml = CreateXML(#PB_Any) 
mainNode = CreateXMLNode(RootXMLNode(xml),"MyList") 

; Create first xml node (in main node)
item1 = CreateXMLNode(mainNode,"FirstItem") 
SetXMLAttribute(item1, "id", "1") 
SetXMLNodeText(item1, "Elephant"+#CRLF$+"Mouse") 

; Create second xml node (in main node)
item2 = CreateXMLNode(mainNode,"SecondItem") 
SetXMLAttribute(item2, "id", "2") 
SetXMLNodeText(item2, "Tiger♥") 

xmlString.s = XMLToString(xml)  
Debug xmlString

CompilerEndIf