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

XML parsing in webMethods

  • 1.  XML parsing in webMethods

    Posted Thu November 10, 2022 04:19 AM

    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


    #webMethods
    #Integration-Server-and-ESB
    #Service-Designer


  • 2.  RE: XML parsing in webMethods

    Posted Thu November 10, 2022 05:48 AM

    Can you share the source file with data minimized?


    #Integration-Server-and-ESB
    #Service-Designer
    #webMethods


  • 3.  RE: XML parsing in webMethods

    Posted Thu November 10, 2022 07:10 AM

    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


    #Integration-Server-and-ESB
    #Service-Designer
    #webMethods


  • 4.  RE: XML parsing in webMethods



  • 5.  RE: XML parsing in webMethods

    Posted Thu November 10, 2022 07:12 AM

    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


    #webMethods
    #Service-Designer
    #Integration-Server-and-ESB


  • 6.  RE: XML parsing in webMethods

    Posted Thu November 10, 2022 07:17 AM

    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


    #Service-Designer
    #Integration-Server-and-ESB
    #webMethods


  • 7.  RE: XML parsing in webMethods

    Posted Thu November 10, 2022 08:07 AM

    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


    #webMethods
    #Integration-Server-and-ESB
    #Service-Designer


  • 8.  RE: XML parsing in webMethods

    Posted Thu November 10, 2022 08:56 AM

    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


    #Service-Designer
    #webMethods
    #Integration-Server-and-ESB


  • 9.  RE: XML parsing in webMethods

    Posted Thu November 10, 2022 10:03 AM

    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 :


    #webMethods
    #Service-Designer
    #Integration-Server-and-ESB


  • 10.  RE: XML parsing in webMethods

    Posted Fri November 11, 2022 01:29 AM