Get "real" XML Child Node Structure

Just starting out? Need help? Post your questions and find answers here.
wayne-c
Enthusiast
Enthusiast
Posts: 335
Joined: Tue Jun 08, 2004 10:29 am
Location: Zurich, Switzerland

Get "real" XML Child Node Structure

Post by wayne-c »

I would like to extract the "real" XML structure text from a child node:

Code: Select all

Test$ = "<test><head/><body><greeting><hello>world</hello><trace>1</trace></greeting></body></test>"
If ParseXML(0, Test$)
	Debug GetXMLNodeText(XMLNodeFromPath(MainXMLNode(0), "body/greeting/hello")) ; --> "world" --> OK
	Debug GetXMLNodeText(XMLNodeFromPath(MainXMLNode(0), "body/greeting/trace")) ; --> "1" --> OK
	Debug GetXMLNodeText(XMLNodeFromPath(MainXMLNode(0), "body/greeting")) ; --> "" --> BAD
	; --> HOW TO GET HERE : "<hello>world</hello><trace>1</trace>" ???
	FreeXML(0)
EndIf
Any ideas? Thank you!
As you walk on by, Will you call my name? Or will you walk away?
wayne-c
Enthusiast
Enthusiast
Posts: 335
Joined: Tue Jun 08, 2004 10:29 am
Location: Zurich, Switzerland

Re: Get "real" XML Child Node Structure

Post by wayne-c »

OK this works, but is there any better way?

Code: Select all

Test$ = "<test><head/><body><greeting><hello>world</hello><trace>1</trace></greeting></body></test>"

If ParseXML(0, Test$)
	Debug GetXMLNodeText(XMLNodeFromPath(MainXMLNode(0), "body/greeting/hello")) ; --> "world" --> OK
	Debug GetXMLNodeText(XMLNodeFromPath(MainXMLNode(0), "body/greeting/trace")) ; --> "1" --> OK
	Debug GetXMLNodeText(XMLNodeFromPath(MainXMLNode(0), "body/greeting")) ; --> "" --> BAD
	; --> HOW TO GET HERE : "<hello>world</hello><trace>1</trace>" ???
	
	If CreateXML(1, #PB_UTF8)
		CopyXMLNode(XMLNodeFromPath(MainXMLNode(0), "body/greeting"), RootXMLNode(1))
		Debug ComposeXML(1, #PB_XML_NoDeclaration)
		FreeXML(1)
	EndIf
	
	FreeXML(0)
EndIf
As you walk on by, Will you call my name? Or will you walk away?
Post Reply