volia17
volia17

Reputation: 938

In WebMethods, How to force document elements to be in order

I have defined a document (from an xsd schema) with some Childs. Those Childs must be in some order, to have correct Xml trnasformation.

When In made some map steps, the element order is not the same as defined in the document reference. How to force that ?

Here the order in te document reference : enter image description here

And here the order after some map stemp : enter image description here

The Datas are correct, but not the order. The problem is that when I make an XmlString, with the documentToXMLString service, from the document, the order is not correct.

Do you have an idea to force the order, at mapping step or at xml generation ?

Upvotes: 1

Views: 2275

Answers (2)

Henning Waack
Henning Waack

Reputation: 410

Have you tried using the parameter "documentTypeName" to provide the fully qualified document type name for the service pub.xml:documentToXMLString? The documentation "IntegrationServer Build-In Service Reference" states:

documentTypeName String Optional Fully qualified name of the document type that describes the structure and format of the output document (for example, examples.rtd:exampleRecord1). You can use this parameter to ensure that the output includes elements that might not be present in document at run time, or to describe the order in which elements are to appear in the resulting XML String.

EDIT: adding example, using wM 9.7

E.g. I have a xml string like:

<?xml version="1.0"?>
<inputdoc>
    <field5>afds</field5>
    <field1>asdf</field1>
    <field3>asdf</field3>
    <field2>asdf</field2>
</inputdoc>

I have an IS doc type with fields field1, field2, field3 and field5 in this order. I have a service where have one input named xmlstring, which contains the above xml string. I call the following services:

  1. pub.xml:xmlStringToXMLNode: mapping my xml string to xmldata input-field
  2. pub.xml:xmlNodeToDocument: converting my node to a document without using "documentTypeName" input-field
  3. pub.xml:documentToXMLString: converting my document instance to a XML string using the input-field "documentTypeName" with my defined IS doc type.

This results in the following XML string:

<?xml version="1.0"?>
<field1>asdf</field1>
<field2>asdf</field2>
<field3>asdf</field3>
<field5>afds</field5>

As you can see the order has changed in the correct way.

Greetings

Henning

Upvotes: 1

TchiYuan
TchiYuan

Reputation: 4278

The easiest is to modify the XSD schema. Use an XSD "sequence" (XSD element Wiki) to defined a specific order for the elements. When that is done, reimport your XSD within webmethods.

If you cannot modify the XSD schema then the other option is create a loop in your flow service and for each PersonalAddress map each field to the fields of your canonical/internal document structure. And in the end, call documentToXMLString on your internal document.

The best option is to design a solution that doesn't depend on the order of the elements in your document.

Hope this helps!

Upvotes: 1

Related Questions