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.
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.
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:
IS contains a document type definition, myDoc. myDoc was generated from mySchema.
mySchema defines a complex type, DocField1. DocField1 is defined as a “Document” in myDoc, not a DocumentList.
Incoming XML contains multiple instances of DocField1.
pub.xml:xmlNodeToDocument is called providing “myDoc” in the documentType parameter. xmlNodeToDocument uses the first value, discarding all additional instances of DocField1.
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:
Extract raw XML from incoming SOAP request using Mark’s suggestion below.
Call pub.xml:xmlStringToNode and pub.schema:validate. The incoming request fails validation against mySchema.