8
Views
1
Comments
Solved by AI
How to parse xml in Outsystems?
Question
Application Type
Reactive

Hi there i am wondering what is the best practice to parse xml in outsystems?

regards

2023-12-26 10-35-28
OutSystems Neo
Staff
Solution by AI
AI Generated

In OutSystems 11 you typically choose between two main approaches, depending on your use case and the XML complexity.


1. XML Extension + XPath (built‑in, very flexible)

Best when:

  • The XML is complex or deeply nested.
  • You only need to extract specific parts (e.g. a subset of nodes).
  • You want full control and performance.

Typical pattern:

  1. Convert Binary to Text (if your XML comes as Binary, e.g. from SOAP/REST/file):

    • Use BinaryDataToText from the BinaryData extension.
  2. Load XML into a DOM:

    • Use XmlDocument_Load_v2 from the XML extension with the XML text.
      This gives you an XmlDocument.
  3. Select nodes with XPath:

  4. Loop through nodes:

    • Use XmlNodeList_Count to get the number of nodes.
    • Loop with a Current index variable and XmlNodeList_Item to get each node.
  5. Extract values from each node:

    • For each element you need (e.g. title, author), use:
      • XmlElement_SelectSingleNode with XPath "title", "author", etc.
      • XmlElement_GetInnerText to get the value.
    • Map them into your own Structures and Lists (e.g. Book list). How to parse XML files with XPath expressions

This approach is “manual” but is the most standard/best-practice way documented by OutSystems for parsing XML.

If your XML is base64‑encoded, first decode using:


2. Forge Components (higher‑level, quicker setup)

a) XML Records (O11)

Best when:

  • You want to map XML directly to Structures / Record Lists.
  • You have complex/nested XML and prefer a model‑driven approach.

XML Records lets you:

  • Design Structures matching your XML hierarchy.
  • Convert XML to Record/Record List in one go and then work with normal OutSystems data.
    It does support nested elements, as long as you correctly define nested Structures that reflect the XML. Parsing complex XML files

This is very convenient for scenarios like:

  • Large XML with repeated items (e.g. products, invoices, addresses).
  • You want to persist each item in an Entity for later processing / retry.

b) XML Prettify (for display only)

If the goal is just to show the XML nicely formatted on screen (with indentation, nodes, etc.), use the XML Prettify O11 Forge component. Display XML content on screen with nodes


Which is “best practice”?

  • To extract data and process it
    Use the XML Extension + XPath or XML Records:

    • Need fine‑grained control / partial extraction → XML Extension + XPath.
    • Want structured mapping from XML to OutSystems records (including nested elements) → XML Records.
  • To present XML to users (read‑only, pretty view) →
    Use XML Prettify.

If you can share whether you mainly want to:

  • persist data (and how complex the XML is),
  • or just view it,

I can suggest the exact flow (server actions, variables, and components) tailored to that scenario.

This answer was AI-generated. Please read it carefully and use the forums for clarifications
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.