Page 1 of 1

Howto convert text to XML

Posted: Fri Jun 27, 2014 4:04 pm
by karu
Can anyone help, i have xml file in text format in string variable. Now if i want to parse XML with PB commands, i need to convert this text value to PB XML. How to do this?

Thanks
Karu

Re: Howto convert text to XML

Posted: Fri Jun 27, 2014 4:52 pm
by STARGÅTE
With ParseXML()

Re: Howto convert text to XML

Posted: Fri Jun 27, 2014 7:38 pm
by karu
Thanks STARGÅTE, but only ParseXML() i fuond from here: http://www.purebasic.fr/english/viewtop ... ML+#p95066
But with this solution i cant use Purebasic XML commands like 'XMLStatus(#XML)', is there other way?

Re: Howto convert text to XML

Posted: Fri Jun 27, 2014 7:48 pm
by STARGÅTE
:?:

PB 5.30 Beta 4:

Code: Select all

Enumeration
	#XML
EndEnumeration

Define Text.s = ReplaceString("<Node Attribute='Value'>Text</Node>", "'", #DOUBLEQUOTE$)

If ParseXML(#XML, Text)
	Debug XMLStatus(#XML)
	*Node = MainXMLNode(#XML)
	Debug GetXMLNodeName(*Node)
	Debug GetXMLAttribute(*Node, "Attribute")
	Debug GetXMLNodeText(*Node)
EndIf

Re: Howto convert text to XML

Posted: Fri Jun 27, 2014 8:25 pm
by karu
Ok, but in 5.2 version?

Re: Howto convert text to XML

Posted: Fri Jun 27, 2014 8:28 pm
by STARGÅTE
PB 5.20:

Code: Select all

Enumeration
   #XML
EndEnumeration

Define Text.s = ReplaceString("<Node Attribute='Value'>Text</Node>", "'", #DOUBLEQUOTE$)

If CatchXML(#XML, @Text, StringByteLength(Text))
   Debug XMLStatus(#XML)
   *Node = MainXMLNode(#XML)
   Debug GetXMLNodeName(*Node)
   Debug GetXMLAttribute(*Node, "Attribute")
   Debug GetXMLNodeText(*Node)
EndIf

Re: Howto convert text to XML

Posted: Fri Jun 27, 2014 8:43 pm
by karu
Thanks STARGÅTE

Re: Howto convert text to XML

Posted: Fri Jun 27, 2014 9:08 pm
by davido
@karu Thank you for the question.
@STARGÅTE Thank you for the answer. :D