PureBasic
PureBasic
Auto-Trim XML Content when Loading
See more XML Examples
This example explains the "autoTrim" argument that is passed to a method such as LoadXml2.Chilkat PureBasic Downloads
IncludeFile "CkXml.pb"
Procedure ChilkatExample()
success.i = 0
xml.i = CkXml::ckCreate()
If xml.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; If autoTrim is 1, then the content inside an leaf element is trimmed.
; For example:
autoTrim.i = 1
CkXml::ckLoadXml2(xml,"<abc><xyz> 123 </xyz></abc>",autoTrim)
Debug CkXml::ckGetXml(xml)
; Output is:
; (notice the SPACE chars before and after "xyz" are trimmed)
; <?xml version="1.0" encoding="utf-8" ?>
; <abc>
; <xyz>123</xyz>
; </abc>
; If autoTrim is 0, then the content inside leaf elements are not trimmed.
autoTrim = 0
CkXml::ckLoadXml2(xml,"<abc><xyz> 123 </xyz></abc>",autoTrim)
Debug CkXml::ckGetXml(xml)
; Output is:
; <?xml version="1.0" encoding="utf-8" ?>
; <abc>
; <xyz> 123 </xyz>
; </abc>
; --------------------------------------------------------------------
; The EmitCompact property controls whether XML is emitted indented (pretty-printed)
; or compact. For example:
; Auto-trim + emit compact:
autoTrim = 1
CkXml::ckLoadXml2(xml,"<abc><xyz> 123 </xyz></abc>",autoTrim)
CkXml::setCkEmitCompact(xml, 1)
Debug CkXml::ckGetXml(xml)
; Output is:
; <?xml version="1.0" encoding="utf-8" ?>
; <abc><xyz>123</xyz></abc>
; No Auto-trim + emit compact:
autoTrim = 0
CkXml::ckLoadXml2(xml,"<abc><xyz> 123 </xyz></abc>",autoTrim)
CkXml::setCkEmitCompact(xml, 1)
Debug CkXml::ckGetXml(xml)
; Output is:
; <?xml version="1.0" encoding="utf-8" ?>
; <abc><xyz> 123 </xyz></abc>
CkXml::ckDispose(xml)
ProcedureReturn
EndProcedure