How is your experience with the OutSystems Community?
31
Views
7
Comments
Solved by AI
Best approach for comparing two XML files in OutSystems 11

We are currently using OutSystems 11 (O11) and have a requirement to compare two XML files.

The expected functionality is as follows:

  1. A user uploads an XML file.
  2. The uploaded XML should be compared against the previously uploaded version of the same XML.
  3. The application should identify and display the differences between the two XML files, such as:
    • Added nodes/elements
    • Removed nodes/elements
    • Modified values
    • Any other relevant structural or content changes

I would like to understand what would be the best and most maintainable approach in OutSystems 11 for implementing this functionality.

Specifically:

  • Is there any Forge component that can be used for XML comparison?
  • Should we implement the comparison logic using C# through an OutSystems Extension?
  • Is there any built-in OutSystems functionality or another recommended approach for this requirement?
  • If a Forge component is recommended, are there any limitations or considerations regarding XML structure, namespaces, file size, or performance that we should be aware of?

I would appreciate any recommendations based on best practices for OutSystems 11, particularly regarding maintainability and performance.

Thank you in advance for your suggestions.

UserImage.jpg
Biswanath Satpathy
Solution

We have done this using writing our customized logic in C# code using extension.

2026-01-28 16-57-48
Mihai Melencu
Champion

Hi @Biswanath Satpathy ,

There is a forge component from 2007, but it's most probably outdated. I would recommend creating your own C# extension, you can use something like this library:  XMLUnit.NET .

UserImage.jpg
Biswanath Satpathy

Thank you for your suggestion. We will explore the proposed approach and work towards resolving the issue accordingly.

UserImage.jpg
Biswanath Satpathy
Solution

We have done this using writing our customized logic in C# code using extension.

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

For O11 there’s no built‑in “XML diff” action, but you can implement this cleanly using existing patterns and/or a small Extension. You basically have three options:


1. XML Records + Custom Diff Logic (all in OutSystems)

If you want to stay 100% in OutSystems and keep it maintainable, I’d start here.

a) Parse both XMLs into Structures

Use the XML Records O11 Forge component to convert each XML into OutSystems Record / Record List structures that mirror the XML tree. Parsing complex XML files

Typical flow on upload:

  1. Store the raw XML in an Entity (text or binary) as your “previous version”.
  2. When a user uploads a new XML:
    • Retrieve the previous version for that “document”.
    • Use XML Records to map OldXML → OldRootStructure.
    • Use XML Records to map NewXML → NewRootStructure.

b) Implement a generic diff between two structure trees

Once both XMLs are represented as Record/Record List structures, you can compare them using normal OutSystems logic:

  • Define a DiffResult structure with fields like:

    • Path (XPath‑like string, e.g. /Invoice/Lines[3]/ProductCode)
    • ChangeType (Added / Removed / Modified)
    • OldValue
    • NewValue
    • NodeType (Element / Attribute)
  • Implement server actions that:

    • Compare lists of elements:
      • Use a key (e.g. Id, Code, Name) to match items in Old vs New.
      • If in New but not Old → Added.
      • If in Old but not New → Removed.
      • If present in both → recurse into child elements / attributes and compare values.
    • Compare simple attributes/values:
      • If OldValue <> NewValue → Modified.

This gives you:

  • A reusable XMLDiff_BuildResult action that returns a list of DiffResult items.
  • A simple table in the UI bound to DiffResult to show all changes (added/removed/modified).

Pros

Cons / considerations

  • You have to define structures reflecting the XML (or generate them, if complex).
  • You must design your matching strategy between nodes (unique identifiers, paths, etc.).
  • Very large XMLs will mean large Record Lists; you may need pagination or limits.

If your XML is “business data” (e.g. invoices, products, configs), this is usually the most maintainable solution.


2. XML Extension + XPath + Diff Logic (semi‑manual XML)

If you prefer to work at XML level (no auto‑mapping to structures), you can use OutSystems’ XML extension with XPath and build the diff yourself. How to parse XML files with XPath expressions

Typical flow:

  1. Convert binary to text (if needed) and load each XML:
    • XmlDocument_Load_v2 → OldDoc, NewDoc.
  2. Traverse the DOM with XPath:
    • For each relevant node in OldDoc, try to find the corresponding node in NewDoc.
    • If not found → Removed.
    • If found but value/attributes differ → Modified.
  3. For nodes present in NewDoc but not in OldDoc → Added.
  4. Accumulate results in a DiffResult list (similar structure as above).

Pros

Cons

  • More “manual” than XML Records.
  • XPath logic can get complex for large schemas.
  • You must carefully handle namespaces (prefixes) in XPath expressions.

This is still maintainable if you encapsulate all logic in a small set of server actions (e.g. XMLDiff_CompareDocuments) and keep the XPath rules clearly documented.


3. C# Extension (using a .NET XML diff library)

If you need a robust, generic XML diff with full support for namespaces, attributes, ordering rules, and want to reuse existing .NET libraries (e.g. Microsoft XML Diff & Patch), then an OutSystems Extension is a good choice.

Approach

  1. Create an Integration Studio Extension (C#).
  2. Wrap a library or your own code that:
    • Accepts two XML strings.
    • Produces:
      • Either a “diff XML” (e.g. an XML with <add>, <remove>, <change> nodes), or
      • A flattened list of changes (that you map to an OutSystems structure).
  3. Expose a simple server action, e.g. XMLDiff_Compare(OldXmlText, NewXmlText) → DiffResultList.
  4. Use this action in your O11 module and display DiffResultList in a table.

Pros

  • Less logic in Service Studio; complex diff handled by tested .NET code.
  • Potentially better performance for very large XMLs, depending on the library.
  • Easier to support advanced cases (e.g. ignore certain nodes, whitespace, ordering).

Cons

  • Requires C# skills and Integration Studio.
  • Debugging is split between OutSystems and .NET.
  • More overhead to deploy and maintain the Extension over time.

If your team is comfortable with C# and you want a “black box” XML diff, this is often the most straightforward.


4. Forge Components for XML Comparison?

Currently, there is no widely‑used, generic Forge component dedicated to XML diff equivalent to “Compare Entity” for entities. I want to compare two structure data and display the different data in list

However, you can combine Forge components:

Limitations / considerations if using Forge components

  • Structure mapping:
    • XML Records expects reasonably well‑structured XML; very dynamic/irregular XML may be harder to map.
  • Namespaces:
    • XML Records supports namespaces, but you have to configure mapping carefully if your XML is heavily namespaced.
  • File size / performance:
    • Very large XMLs (MBs with tens/hundreds of thousands of nodes) can consume significant memory if fully converted to Record Lists.
    • You may need:
      • Streaming / incremental processing.
      • Limits on file size.
      • Background processing (e.g. timers) instead of synchronous comparison on screen.
  • Upgrade path:
    • Check Forge component compatibility with your O11 version and any future upgrade plans.

Given your requirements (track added/removed/modified nodes and values, show differences to the user, O11, maintainable):

  1. Persist XML versions:

    • Create an Entity XmlDocument with fields like:
      • DocumentKey (e.g. a business key or filename).
      • Version (integer).
      • XmlContent (Text or Binary).
      • UploadedOn, UploadedBy.
  2. Compare on upload:

    • When a new version is uploaded:
      • Fetch previous version by DocumentKey.
      • If none, just store as version 1.
      • Else:
        • Either:
          • Option A (pure OutSystems): Use XML Records → structures → your own diff logic.
          • Option B (Extension): Call XMLDiff_Compare in C#.
  3. Generate a DiffResult list:

    • Structure with:
      • Path, ChangeType, OldValue, NewValue.
    • Use this to drive your UI (table, grouping by section, etc.).
  4. Optionally:

If you don’t have strong C# experience, I’d start with XML Records + custom OutSystems diff; it’s very maintainable, transparent to OutSystems developers, and leverages the platform’s strengths. If later you hit performance or need more advanced comparison rules, you can encapsulate the diff in a C# Extension and keep the rest (storage, UI, flows) unchanged.

This answer was AI-generated. Please read it carefully and use the forums for clarifications
2023-09-21 12-55-43
SIRAJKHILJI

We have 5 options.

For an O11 enterprise application, I'd choose:

Option 1 — C# Extension + standard XML APIs ⭐⭐⭐⭐⭐

Best when you need complete control and long-term maintainability.

Option 2 — C# Extension + mature XML diff library ⭐⭐⭐⭐⭐

Best if the library already provides exactly the structural diff semantics you need.

Option 3 — Forge component ⭐⭐⭐

Good if you find a mature, actively maintained component that meets your exact XML requirements.

Option 4 — String comparison ⭐

I would avoid this for a true XML comparison.

UserImage.jpg
Biswanath Satpathy

Thank you for your response. we have done this using C# extension.

2023-09-21 12-55-43
SIRAJKHILJI

You can use the Forge components below


https://www.outsystems.com/forge/component-overview/23816/filediff-tool-o11

https://www.outsystems.com/forge/component-overview/47/compare2xml-o11

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.