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

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.

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.


@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"?>

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:element name="people" maxOccurs="unbounded" minOccurs="0">
              <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"/>

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?


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?