Options

Problem with < and > in XML file

LamzaLamza Member Posts: 8
edited 2011-11-10 in NAV Three Tier
I'm trying to parse an XML file in NAV which has < and > characters instead of < and > as element definition. I'm accessing the file through a web service. Problem is that I can't access those elements because they're interpreted as text and not as valid XML elements. Any ideas?

Comments

  • Options
    SogSog Member Posts: 1,023
    So does your explination means that
    I xml consists of:
    <mainelement>
      <subelement>
         <inner>tekst tekst 1 > 0</inner>
    <inner>other tekst 20 < 30</inner>
    </subelement></mainelement>
    
    if I is the case then you ought to parse > and < with a function and return > or <.

    II xml consists of
    <mainelement>
    <subelement>
    </subelement>
    <mainelement>
    
    IF II is the case, then it's not a valid xml file, and no webservice will know what the elements are and what not.
    < and > are meant to replace < and > in the file when they are not a part of the element because else an xml could be parsed incorrectly because < and > are inherent to an element. without these characters you have no xml-file.
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • Options
    LamzaLamza Member Posts: 8
    Yes, I know when these escape characters should be used and in my case they're not used properly, your case No. 2. But, this is a well known web service of a National Bank that provides current currency exchange rates and it's used by many parties so I'm worried that I'm the one who's doing something wrong, but don't know what?!
  • Options
    LamzaLamza Member Posts: 8
    Strange thing is that not all of the elements have escape characters attached. First couple of elements in the elements hierarchy are properly formated, but all of the rest aren't.
  • Options
    LamzaLamza Member Posts: 8
    All of the XML data I need is part of a SOAP Envelope. The elements regarding the SOAP envelope itself are properly formated, but the data I need is formated as string inside the last SOAP envelope element.
  • Options
    vaprogvaprog Member Posts: 1,118
    Lamza wrote:
    All of the XML data I need is part of a SOAP Envelope. The elements regarding the SOAP envelope itself are properly formated, but the data I need is formated as string inside the last SOAP envelope element.
    So, to me it looks like you need to retrieve that string (in a Way that converts those entities back to characters) and then feed it to some XML processor (MSXML, XMLPort) as an XML document.
  • Options
    LamzaLamza Member Posts: 8
    Yes, but the problem is that the string in question is to big for the string variable of C/AL, so I'm trying to do something with the BigText variable.
  • Options
    abartonicekabartonicek Member Posts: 162
    I have the same problem.
    Content of the SOAP message is treated as plain text (> instead <) so my way around that problem was to use XmlDoc.text method to get the data.

    XmlHTTP is defined as 'Microsoft XML, v6.0'.XMLHTTP
    XmlDoc is defined as 'Microsoft XML, v6.0'.DOMDocument60


    The code for getting data from SOAP is:
    XmlDoc.load(XmlHttp.responseBody);
    XmlDoc.loadXML('<Return>'+XmlDoc.text+'</Return>');
    
    I added dummy top level node <Return> just in case so that the XML inside SOAP message is correct (in case it hasn't top level node).

    The problem is that the XmlDoc.text apparently doesn't handle long strings so I can't get the SOAP message data out of the XmlHTTP response.

    BigText can't solve that problem because it's not the problem in storing text into a variable.
    Anybody has any other idea we could try?
    Better to be critical then self-critical :)
  • Options
    max_hlmax_hl Member Posts: 13
    This way :wink:

    send request:
    xmlhttp.send(xmldoc); 
    IF xmlhttp.status = 200 THEN BEGIN 
      xmldoc := xmlhttp.responseXML;
    
      ProcessResponse(Rec,xmldoc);
      Response.CREATEINSTREAM(InStr);
      xmldoc.save(InStr);
    END ELSE
      ERROR(xmlhttp.statusText);
    
    ProcessResponse(VAR Req, VAR xmldoc)
    // remove soap envelop
    node := xmldoc.selectSingleNode('Soap:Envelope/Soap:Body/YOURFUNCTIONCALL_Result/msgOut');
    
    body := '<?xml version="1.0"?><resp/>';
    
    CREATE(xmldoc2,TRUE,TRUE);
    
    xmldoc2.loadXML(body);
    node2 := xmldoc2.documentElement;
    node2.appendChild(node);
    
    xmldoc.loadXML(body);
    
    // unescape
    body := '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1">' +
              '<xsl:template match="resp">' +
                '<xsl:value-of select="." disable-output-escaping="yes"/>' +
              '</xsl:template>' +
            '</xsl:stylesheet>';
    
    CREATE(XSLStyle,TRUE,TRUE);
    XSLStyle.loadXML(body);
    
    CREATE(XSLTemplate,TRUE,TRUE);
    XSLTemplate.stylesheet := XSLStyle;
    Processor := XSLTemplate.createProcessor;
    Processor.input := xmldoc2;
    Processor.output := xmldoc;
    IF NOT Processor.transform THEN
      ERROR(Text002);
    

    vars:
    XSLStyle	Automation	'Microsoft XML, v6.0'.FreeThreadedDOMDocument60	
    XSLTemplate	Automation	'Microsoft XML, v6.0'.XSLTemplate60	
    Processor	Automation	'Microsoft XML, v6.0'.IXSLProcessor
    
Sign In or Register to comment.