XML parsing in webMethods

Greetings Community,

I ran into a problem parsing XML file which isn’t giving me the results I expect.

high level steps of flow service are as following:

  1. read file using
    image

  2. convert xml string to XmlNode
    image

  3. Get iterator against XmlNode (where its criteria is assigned value “Customer”)
    image

  4. invoke getNextXmlNode inside REPEAT flow step
    image
    following is the output of this step in debug view:
    image

  5. Invoke xmlNodeToDocument
    image
    following is the output of this step in debug view:
    image

  6. Invoke documentToXMLString
    image
    following is the output of this step in debug view:
    image

  7. Create new string in a MAP flow set as following:
    “<Customer>” + value of xmldata + “</Customer>”

  8. write value of newly created string (in above step) to a file on local disk using:
    image

Now actual content (xml) written to file (in above step) is as following:
image

Now problem is that the xml data written to local disk file is not reflecting attribute “CustomerID” correctly in xml as highlighted in below screenshot:
image

I wanted to seek help from respected community members in this regard. Can some one please guide me how I can have the CustomerID attribute written correctly in output file instead of the way it is currently being written (highlighted in yellow color in above screenshot)

Thanks

For your reference following is the actual source xml data sample:
image

Can you share the source file with data minimized?

Create a documentType for your customer info and use that documenTypeName. use that documentTypeName in XML BIS
image

pub.xml:xmlNodeToDocument

pub.xml:documentToXMLString

You can write the xmldata string to file.

Input and output look like below for me

you mean this?

No need for the source file. I created my own source data and tested it. I posted the solution here. Can you take a look at my previous comment

Thanks @Mohankumar_N !!
but if I change my criteria in the Iterator, then should have to create another DocumentType for another entity.
means I have to put everytime… like its a solution for one entity only

I assumed the criteria is static.I tried the dynamic approach. Let’s see if this works for you

You have to place the fields inside a wrapper document so documentToXMLString assigns the attribute properly.
image

if you cannot use documentTypeName then we have to go for the java service to create a wrapper document

pub.xml:xmlNodeToDocument


Jave service to create a wrapper.

Java service

// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();		
// document
IData document = IDataUtil.getIData( pipelineCursor, "document" );
String name = IDataUtil.getString( pipelineCursor, "name" );
pipelineCursor.destroy();

IData output = IDataFactory.create();
IDataCursor outputCursor = output.getCursor();
IDataUtil.put(outputCursor, name, document );
outputCursor.destroy();
	
// pipeline
IDataCursor pipelineCursor_1 = pipeline.getCursor();		
IDataUtil.put( pipelineCursor_1, "output", output );
pipelineCursor_1.destroy();

output has a wrapper document with the name of the name passed as input

I got you !!!
but it only creates a named document according to the (given) criteria, what about the different variable/names of the entity that lie under the document?
for your understanding, two different nodes :
image

All the child elements inside the Customer document or Order document will be taken. Have you tried this solution on your server with your source file?

Criteria is Customer. Input and result :

Criteria is Order. Input and result :

Yes, Thanks for helping !

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.