Reading and generating XML
TXmlManager():New(); Parse(cXml); Save2String()Parses and serializes XML with TXmlManager.
Overview
TXmlManager represents an XML tree that can be traversed and serialized. Parse returns logical: inspect the tree only after success; Error provides failure diagnostics. Save2String generates XML from the current tree without promising byte-for-byte input equality. Documentation deprecates XmlParser and recommends TXmlManager. The community TLPP example handles Parse and reads an XPath node; only creation and error handling are adapted into this minimal AdvPL example. (Sources: refs. 1–5.)
Syntax
TXmlManager():New(); Parse(cXml); Save2String()Commented example
#Include "Protheus.ch"
User Function Ed506()
Local oXml := TXmlManager():New()
Local cXml := "<item><code>ED01</code></item>"
// Check parsing before using the tree.
If oXml:Parse(cXml)
ConOut(oXml:Save2String())
Else
ConOut(oXml:Error())
EndIf
FreeObj(oXml)
Return NilOn success, prints XML containing item/code with ED01. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Define encoding, escape dynamic content and bound input size. Parsing does not replace schema or business validation. Release the object on failure paths too.
- Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.