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

Unable to Parse ampersand while converting XML String to Document

  • 1.  Unable to Parse ampersand while converting XML String to Document

    Posted Thu March 28, 2013 09:23 AM

    Hello,
    I have an XML string as Input to a service.
    The XML contains a string which has ‘&’ [ampersand] in it.
    Example: Engineering & Management Services

    I am converting this XML String to Node (using pub.xml:xmlStringToXMLNode) and then to Document ( using pub.xml:xmlNodeToDocument).

    While converting to Document, I am getting the below error:

    com.wm.app.b2b.server.ServiceException: [ISC.0042.9332] Malformed entity reference: & Management Services


    I have tried using encoding = UTF-8 and UTF-16 but got the same results.

    For debugging purpose, when I change the “&” to “&” in the source XML string then it works perfectly, but as a solution this cannot be taken, as no change in source XML is allowed.

    Any suggestion for this solution is really appreciated.

    Thanks


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


  • 2.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Thu March 28, 2013 11:07 AM

    Hi Soumodip,
    In the xsd of this xml for this particular field you can define accepted special character. Once you define then it should not throw this error.

    Regards,
    Vikas


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


  • 3.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Thu March 28, 2013 12:11 PM

    Hi Soumodip,

    The above scenario is an invalid xml character according to XML 1.0 Spec, so if possible tell the source to send with a valid html character(&amp as you mentioned).
    If not set the below watt property to disable validation.
    watt.server.xml.enforceEntityRef=false

    My $.02,
    Niteesh


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


  • 4.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Thu March 28, 2013 09:00 PM

    The source MUST change the XML to convert & (and other specific characters used for markup) to the proper entity character. E.g. change & and &. It is not valid XML otherwise and there is nothing that you should do on your side to accomodate that invalid XML.


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


  • 5.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Thu March 28, 2013 09:00 PM

    I would strongly advise against using this setting. You should tell the source that they MUST produce valid XML.


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


  • 6.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Mon April 01, 2013 10:21 AM

    Thanks All for your valuable feedback & suggestions.


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


  • 7.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Mon March 23, 2015 06:34 AM

    Hi All,

    I m also facing the same error in my code .Source is sending the XML with &.
    As per nitesh i set the below property,

    watt.server.xml.enforceEntityRef=false

    But still getting the same error.Source is not able to correct this.Since webMethods needs to allow this special charaters in the xml.Any one please suggest.


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


  • 8.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Mon March 23, 2015 07:52 AM

    Pass the xml string to find and replace ‘&’ to ‘amp’ ‘and’


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


  • 9.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Mon March 23, 2015 08:34 AM

    Hi Mahesh,

    Thanks for your info.

    Is it possible to accept the special characters without changing the source XML format?

    Regards,
    Sakthi


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


  • 10.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Mon March 23, 2015 09:09 AM

    According to me watt.server.xml.enforceEntityRef=false setting should have fixed your problem. Did you reboot the Is after giving this setting.


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


  • 11.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Mon March 23, 2015 09:12 AM

    Option 3: Use the pub.string:HTMLEncode pass your input xml string to this service first and then process it further.


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


  • 12.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Mon March 23, 2015 09:12 AM

    Yes restarted.But still facing same issue…


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


  • 13.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Mon March 23, 2015 09:20 AM

    yea.i tried that,but it looks like whole xml format got changed.i m getting the error while converting XML to node service ,since it is not able to recognize the ‘&’ .so it is failing.


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


  • 14.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Mon March 23, 2015 09:23 AM

    Option 3: Use the pub.string:HTMLEncode pass your input xml string to this service first and then process it further.

    Let me know your results.


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


  • 15.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Mon March 23, 2015 09:24 AM

    Attach your xml file I will see that is the issue. Talk to you soon.


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


  • 16.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Mon March 23, 2015 10:59 AM

    Hi Mahesh,

    Here is the sample XML for you,

    Arun & Kumar Suman & Kumar

    Error occuring when it tries to convert XML node to document .

    and Currently we are using the Version 7.1.2

    Regards,
    Sakthi


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


  • 17.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Mon March 23, 2015 12:37 PM

    You have not read and understood my earlier post :lol:

    Map the xml data to string replace service and replace & with

    & amp ; (no spaces)

    Map the value of string replace to xml string to node and then node to document.

    Or before passing your xml data to xml string to node repalce & with amp or and.


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


  • 18.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Mon March 23, 2015 12:51 PM

    Hi Mahesh,

    I already did that ,it is passing the node to document service without any error,But looks like document getting generated as empty and also it is not an understandable format,
    and as you said we unable to replace the & with & as source is only sending the XML data with ‘&’

    However we have to accept special character & from source in any case without changing the XML.


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


  • 19.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Mon March 23, 2015 01:45 PM

    how do you receive the xml string in webMethods?

    I have to check other alternate options and let you know. I remember doing this in the past projects. Stay tuned!


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


  • 20.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Tue March 24, 2015 12:18 AM

    Hi Mahesh,

    we are receiving the XML via MQ.

    Regards,
    Sakthi


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


  • 21.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Tue March 24, 2015 04:17 AM

    As far I know only options is to Escape Special Characters. You can write a java code to handle this.

    Doing the above will not change your xml string that you receive from your partner. Contact me on my email for more details and discussion.


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


  • 22.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Thu March 26, 2015 05:40 PM

    sakthi , first of all & is not valid to be used within XML. it is not only the parsing issue within webMethods but any other parser would not parse the xml if it has the special character &.

    I think the only solution would be to write a Service to accept the xml as input, replace & with the valid escape charters & and return the valid xml for you to parse.


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


  • 23.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Thu March 26, 2015 10:57 PM

    Hi All,

    I resolved this issue by replacing ‘&’ with '& amp;'and i m not seeing any failures now.

    Regards,
    Sakthi


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


  • 24.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Mon September 26, 2016 07:12 AM

    I have a problem here - the xml received via file polling port to webMethods.

    As we use file polling - the first service is xmlnode to document conversion - and this service fails when we have an & in xml .

    Any ideas ?

    We can’t do replace here being first service use - any better way to handle xml with & via file pollling ?


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


  • 25.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Mon September 26, 2016 02:10 PM

    try passing the ffdata stream to stream to string (see if you get a valid xml string) if yes, then invoke xml string to node and proceed further.


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


  • 26.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Fri September 30, 2016 08:19 AM

    Are you still having this issue ? I didn’t see any further comments. Try as he said.

    THanks,


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


  • 27.  RE: Unable to Parse ampersand while converting XML String to Document

    Posted Mon October 24, 2016 02:53 AM

    Actually the issue faced now is as below in the sent step for RN

    :Send_External_Response_Document failed. com.wm.app.b2b.server.ServiceException: com.wm.estd.rosettaNet.RosettaNetException: com.wm.estd.rosettaNet.RosettaNetException: com.wm.estd.common.trp.IPException: Error: Error while executing service wm.estd.common.util:documentToRecords. Error Message: com.wm.lang.xml.WMDocumentException: [ISC.0042.9325] Element is missing end tag Suggested Action: Level: Level: Service Call Stack: org.w3c.dom.DOMException: com.wm.lang.xml.WMDocumentException: [ISC.0042.9325] Element is missing end tag at com.wm.lang.xml.Document.completeLoadDOM(Document.java:888) at com.wm.lang.xml.Node.getFirstChild(Node.java:1330) at com.wm.lang.xml.Document.getFirstChild(Document.java:1324) at com.wm.estd.common.util.DocumentToRecordService.recursiveCollect(DocumentToRecordService.java:517) at

    Service -wm.prt.dispatch:handleTransition
    Here ProprietaryDocumentIdentifier is having & and hence the problem .
    Any suggestions on this ?


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