IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

Webmethods: Question about XML converting to JSON (Validation and others)

  • 1.  Webmethods: Question about XML converting to JSON (Validation and others)

    Posted Tue November 16, 2021 03:04 AM

    Hello, I’ve got several questions in regards of XML in webMethods. Beforehand, I was more concerned on JSON, now it’s XML’s turn.

    First, does every XML needs to have ‘root’ attribute in it? This is because in case I used ‘convert JSON to document’ and then ‘convert document to XML’, they’ll never have ‘root’ attribute, and it would be considered improper. Any work arounds? (As in, should I edit the middle document to have root attribute first?)

    Second, how do we validate an XML, similar to validating JSON with pub.json.schema.validate? XML doesn’t seem to have anything resembling validation, even for its schema (XSD)…

    Third, usually my go-to method to convert from XML to JSON is like this

    1. xmlStringToXMLNode
    2. xmlNodeToDocument
    3. documentToJSONString

    The thing is, using this method has no string/numeric recognition, if they find a number, they’ll always treat it as a string and the end result would be something like “age”:“21” instead of “age”:21. How do I get around that? Or is there another route I can take for that?

    Thanks! If I have further questions, I’ll add in the replies.


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 2.  RE: Webmethods: Question about XML converting to JSON (Validation and others)

    Posted Tue November 16, 2021 07:09 AM

    Hi Kristian,

    best way for validating XML is to create the XSD schema outside wM and then create the DocType by importing this schema into IS via Designer.

    For validation there is a service pub.schema:validate, which takes the document to be validated and either docType or schema as input.

    See IS Built-In-Services Reference for further information.

    Regards,
    Holger


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 3.  RE: Webmethods: Question about XML converting to JSON (Validation and others)

    Posted Tue November 16, 2021 09:44 PM

    @Holger_von_Thomsen Hmmm, I’m having trouble in testing this out.

    First off, here’s my proposed input XML. We’ll call this sample.xml

    <?xml version="1.0"?>
    <root>
    <people>
    <firstName>Joe</firstName>
    <lastName>Jackson</lastName>
    <gender>male</gender>
    <age>28</age>
    <number>7349282382</number>
    </people>
    <people>
    <firstName>Emily</firstName>
    <lastName>Jones</lastName>
    <gender>female</gender>
    <age>24</age>
    <number>456754675</number>
    </people>
    </root>
    

    I used an online converter to create a schema, resulting sample.xsd

    <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="root">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="people" maxOccurs="unbounded" minOccurs="0">
    <xs:complexType>
    <xs:sequence>
    <xs:element type="xs:string" name="firstName"/>
    <xs:element type="xs:string" name="lastName"/>
    <xs:element type="xs:string" name="gender"/>
    <xs:element type="xs:byte" name="age"/>
    <xs:element type="xs:long" name="number"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    

    Then I used webMethods to create an XML Document Type using sample.xsd. For some reason, it resulted this:

    noNamespace (folder)
    noNamespace/elements (subfolder)
    noNamespace/elements/root (object)
    noNamespace/root (object)
    noNamespace/schema (schema)

    Now which one from this do I pick for conformsTo? I tried all of them and none of them has any results. Am I actually doing the ‘Create XML Document Type’ wrong?

    Thanks.


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 4.  RE: Webmethods: Question about XML converting to JSON (Validation and others)

    Posted Thu November 18, 2021 08:12 AM

    Hi Kristian,

    looks like there several issues with the xsd.

    I think that the field age should be defined as integer instead of byte.
    Additionally you should set elementFormDefault to unqualified, this avoids the noNamespace to be generated.
    Otherwise all the tags in XML need to have the “noNamespace:” prefix.

    Can you provide some screenshots from the generated nodes for verification?

    Regards,
    Holger


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB