Share your advanced knowledge/code with the community.
User avatar
eddy
 
Posts: 124
Joined: Thu Mar 27, 2014 8:34 am

XMLToString

by eddy Fri Apr 11, 2014 10:07 pm

- 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
Return to Tricks 'n' Tips

Who is online

Users browsing this forum: No registered users and 2 guests