Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

Reading and generating XML

TXmlManager():New(); Parse(cXml); Save2String()

Parses and serializes XML with TXmlManager.

Reading and generating XMLAdvPL
01 · OVERVIEW

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.)

02 · SYNTAX

Syntax

TXmlManager():New(); Parse(cXml); Save2String()
03 · PRACTICAL EXAMPLE

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 Nil
Expected result

On 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.

BEST PRACTICES
  • 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.

Related content

REFERENCES
  1. TOTVS. Classe+TXmlManager. TDN. Accessed on 2026-10-27.
  2. TOTVS. TXmlManager%3AParse. TDN. Accessed on 2026-10-27.
  3. TOTVS. TXmlManager%3ASave2String. TDN. Accessed on 2026-10-27.
  4. TOTVS. XmlParser. TDN. Accessed on 2026-10-27.
  5. Atilio/Terminal de Informação. Exemplo TLPP video0223; commit 7d275a7. Accessed on 2026-10-27.
Status
Under review
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha