487
Views
13
Comments
Solved
[XML Records] XMLtoRecordList namespaces conversion problems
Question
xml-records
Service icon
Forge asset by Afonso Carvalho

Hello,

The xml I want convert to a record list looks like this: 

<n1:Message xmlns:base="http://namespace.com/test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://namespace.com/test2" xmlns:n1="http://namespace.com/test2" xsi:schemaLocation="http://namespace.com/test.xsd">
  <base:OrderId>04883999</base:OrderId>
  <base:Version>1</base:Version>
  <n1:Assignment>
    <n1:Code>87108758327</n1:Code>
    <n1:Tasks>
      <tns:Number>1</tns:Number>
      <tns:Description>Intake</tns:Description>
    </n1:Tasks>
  </n1:Assignment>
</n1:Message>


I'am having troubles converting the xml to a record list. 

1) Is it possible to convert this xml with multiple namespaces?

2) If so, how does the configuration of the XMLToRecordList look like?

3) Or do you suggest to delete the namespace prefixes (e.g. n1: or tns) before using the XMLToRecordList?


Kind regards,

Rik

2019-06-15 21-39-22
Afonso Carvalho
 
MVP
Solution

Hi,

It's possible to do this, but it's a bit awkward. I hardcoded an example of an XML with multiple namespaces into the demo espace:


Attached the OML for a code example (ReadXML action in the XmlToRecordList page), let me know if you have any questions.

XMLRecordsDemowithnamespacechanges.oml
UserImage.jpg
RikVDN

Thanks

This works although the xml is actually much bigger so its getting complex and isn't well maintainable.

For later readers of this topic; use Record mode = "C" to get the nesting you want.

2018-05-14 06-39-33
Richard van Osnabrugge

Thanks, this example helped me a lot!

2019-06-15 21-39-22
Afonso Carvalho
 
MVP

Nice. I completely forgot about RecordMode, I don't think I've ever had the need to use it. I'll update the FAQ since this is a common enough use case, and like you've discovered, it's not immediately obvious how you're supposed to implement this.

UserImage.jpg
Dieusaert Gregory

Hi,

Can  somebody explain to me how you got this filled ? 

I can't find anything in the project here above.

I've been searching for days to have multiple prefixes like this:

<Invoice xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"           xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"    xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">    <cbc:CustomizationID>urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0</cbc:CustomizationID>

  <cbc:ProfileID>urn:fdc:peppol.eu:2017:poacc:billing:01:1.0</cbc:ProfileID>

    <cbc:ID>Snippet1</cbc:ID>

    <cbc:IssueDate>2017-11-13</cbc:IssueDate>

    <cbc:DueDate>2017-12-01</cbc:DueDate>

    <cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode>


Can Someone help me?

Error @ outsystems : 'cbc' is an undeclared prefix. Line 1, position 74. 

2019-06-15 21-39-22
Afonso Carvalho
 
MVP

Hello Dieusaert,

RikVDN's code snippet illustrates an example of multiple namespaces in the same XML file. How are you filling out your XMLConfig input structure? Would you be willing to share a code sample for everyone to look over?

UserImage.jpg
Dieusaert Gregory

Hello Afonso Carvalho,

It is a great example and i learned a lot from it, but i can't find where to put multiple prefixes in the config, also not in the example or i over looked it..

This is my config:

Now i get the error that cbc is not defined , true.. but where can i define cbc ? 

Here is an example of the xml i need to generate:

https://github.com/OpenPEPPOL/peppol-bis-invoice-3/blob/master/rules/examples/base-example.xml

Greetings

2019-06-15 21-39-22
Afonso Carvalho
 
MVP

I believe you need to use the Namespace input: "urn:oasis..." seems to be a value in your example, and not a namespace.

UserImage.jpg
Dieusaert Gregory


<Invoice xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"

xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDataTypes-2"

xmlns:udt="urn:oasis:names:specification:ubl:schema:xsd:UnqualifiedDataTypes-2"

xmlns:ccts="urn:un:unece:uncefact:documentation:2"

xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">

These are the namespaces i need to add.. 

On this moment only the last xmlns=""  is added

How can i add xmlns:cbc or xmlns:cac and so on? In the example above it is not explained where.. 

example in microsoft docs..

https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms754539(v=vs.85)#:~:text=about%20XML%20namespaces.-,What%20Is%20an%20XML%20Namespace%3F,elements%20with%20the%20same%20name.

This line:

<RecordList xmlns:xxx="http://namespace.com/test" xmlns:n1="http://namespace.com/test2" xmlns:n2="http://namespace.com/test3" >

Where did you define this?

UserImage.jpg
Dieusaert Gregory

nobody?

2020-03-30 22-22-21
Nick MATES

I'm sorry for this potentially remedial question but I am absolutely smashing my head against a wall while trying to use this as a template for a new integration as I believe it to be similar to the problem I am facing : 

1. I have an XML output structure with multiple namespaces

2. I've updated to what I believe to be the correct configs on the XmlToRecordList

3. I am still receiving a exception response of : 'ns4' is an undeclared prefix, despite believing that I have declared it in the Namespace/EffectiveName attributes of XmlConfig[0]

I've attached an example .oml with a single button to replicate the behavior

Side Note : Despite this looking like PII I can assure you this is test data and links back to no individual as it is a sample report.

zTestExample.oml
2020-03-30 22-22-21
Nick MATES

I think I may have finally answered my own question minutes after throwing in the towel after almost a full day. 

  1. IgnoreXMLDeclearationAndNS has to be set to false to ensure that the namespaces are properly included
  2. BypassRootRecordListNode has to be set to false to ensure that the root note is evaluated
  3. This causes a "The current node (xml) does not match the record definition (PersonResultsPageV3)" because it's attempting to read the declaration as the root node
    1. I had previously seen this error thinking that "(xml)" was a generic term but I believe it was actually attempting to read the "xml" in the declaration as a root element
  4. To resolve this I did a Replace() on the declaration with a blank string
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.