webMethods

webMethods

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

Extract raw XML from com.wm.lang.xml.Node?

  • 1.  Extract raw XML from com.wm.lang.xml.Node?

    Posted Mon February 27, 2006 11:20 PM

    Does anyone know how I can get the raw XML associated with an XML Node?

    I’m calling pub.soap.utils:getBody which returns an XML Node (com.wm.lang.xml.Node) and I’d like to extract the entire XML, not just specific values. I could use pub.soap.utils.soapDataToString and then extract everything in the SOAP-BODY tag but I thought there might be a better alternative using queryXMLNode. I’m surprised there isn’t a pub.xml.xmlNodeToString service.

    Thanks,
    Fred


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


  • 2.  RE: Extract raw XML from com.wm.lang.xml.Node?

    Posted Mon February 27, 2006 11:28 PM

    Fred,

    Try pub.xml:queryXMLNode with the XQL query “/source()”. The alternative is to convert the node to a document with pub.xml:xmlNodeToDocument and then use pub.xml:documentToXMLString to get the string.

    Mark


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


  • 3.  RE: Extract raw XML from com.wm.lang.xml.Node?

    Posted Tue February 28, 2006 03:18 PM

    Thanks, that did the trick! Regarding your other suggestion, I encountered a “feature” of pub.xml:xmlNodeToDocument and pub.schema:validate that prevent me from using the two in conjunction. Here’s the scenario:

    1. IS contains a document type definition, myDoc. myDoc was generated from mySchema.
    2. mySchema defines a complex type, DocField1. DocField1 is defined as a “Document” in myDoc, not a DocumentList.
    3. Incoming XML contains multiple instances of DocField1.
    4. pub.xml:xmlNodeToDocument is called providing “myDoc” in the documentType parameter. xmlNodeToDocument uses the first value, discarding all additional instances of DocField1.
    5. To validate the incoming XML request I call pub.xml:documentToXMLString, pub.xml:xmlStringToNode and finally pub.schema:validate. The document validates successfully when in fact multiple instances of DocField1 should fail validation against mySchema.

    Your first suggestion might be to use the “arrays” parameter in pub.xml:xmlNodeToDocument to ensure that DocField1 is always generated as a DocumentList. If this happened then pub.schema:validate would work correctly. Unfortunately, this logic belongs to a custom soap processor that must handle any incoming XML document defined in mySchema. Therefore, I will never know until runtime what values belong in arrays. I can derive the document type name (which corresponds to names in the schema), but as you can see above this approach doesn’t work.

    Solution:

    1. Extract raw XML from incoming SOAP request using Mark’s suggestion below.
    2. Call pub.xml:xmlStringToNode and pub.schema:validate. The incoming request fails validation against mySchema.

    Thanks,
    Fred


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