Code: Select all
FormatXML(#XML, Flags [, IndentStep])
IndentStep (optional) : The indent to apply (in characters) when using the #PB_XML_ReFormat or #PB_XML_ReIndent flags
Code: Select all
FormatXML(#XML, Flags [, IndentStep])
IndentStep (optional) : The indent to apply (in characters) when using the #PB_XML_ReFormat or #PB_XML_ReIndent flags
Code: Select all
xml = CreateXML(#PB_Any)
mainNode = CreateXMLNode(RootXMLNode(xml), "Zoo")
item = CreateXMLNode(mainNode, "Animal")
SetXMLAttribute(item, "id", "1")
SetXMLNodeText(item, "Elephant")
item = CreateXMLNode(mainNode, "Animal")
SetXMLAttribute(item, "id", "2")
SetXMLNodeText(item, "Tiger")
FormatXML(xml, #PB_XML_ReFormat, 4)
XML$ = ComposeXML(xml)
Debug XML$
XML$ = ReplaceString(XML$, " ", #TAB$)
Debug XML$
No, that does not work as the 4 spaces may occur inside regular node text or inside CDATA.infratec wrote:Use an ident which does not occure in normal text (4 in my example) and replace it afterwards with the #TAB$
XML$ = ReplaceString(XML$, " ", #TAB$)
[/code]
Code: Select all
FormatXML(xml, #PB_XML_ReFormat, 100)
XML$ = ComposeXML(xml)
Debug XML$
XML$ = ReplaceString(XML$, Space(100), #TAB$)
Debug XML$
Code: Select all
Procedure FormatXMLWithTabs(XML.i)
FormatXML(XML, #PB_XML_ReFormat)
Text.s = ComposeXML(XML)
nSpaces.i = 4
IndentStr.s = Space(nSpaces)
While (FindString(Text, IndentStr))
nSpaces * 2
IndentStr = Space(nSpaces)
Wend
FormatXML(XML, #PB_XML_ReFormat, nSpaces)
ParseXML(XML, ReplaceString(ComposeXML(XML), IndentStr, #TAB$))
EndProcedure
CreateXML(0)
*Main = CreateXMLNode(RootXMLNode(0), "main")
*Child = CreateXMLNode(*Main, "child")
For i = 1 To 3
CreateXMLNode(*Child, "sub")
Next i
*Child = CreateXMLNode(*Main, "child")
For i = 1 To 3
CreateXMLNode(*Child, "sub")
Next i
FormatXMLWithTabs(0)
SetCurrentDirectory(GetTemporaryDirectory())
SaveXML(0, "temp.xml")
RunProgram("temp.xml")