Problem with large XML document received from Web Service

SkeeveSkeeve Member Posts: 33
Hi All,

I am retrieving an XML document from a web service (which works fine). The XML doc looks something like this:

xml.jpg

In NAV, I am using 'Microsoft XML, v6.0'.DOMDocument to retrieve it and save it to disk. So far so good.

What I have to do, however, is access the various elements within <transaction> to create an order in NAV. I cannot for the live of me make that work. Stuff like "SelectSingleNode" fails. So I tried to somehow read the content (or rather the value) of the <transaction> element into a new DOM in order to be able to navigate and process it. I have tried many ways to do it and it all errors out with "The length of the text exceeds the length of the string buffer" - since NAV (still) is limited to 1024 characters for string variables.

So I did:
Node := XMLDoc.selectSingleNode('Envelope/Body/GetTransactionResponse/transaction');

which actually works. But then I do this:
XMLDoc.load(Node.xml);

or
XMLDoc.loadXML(Node.text);

or
XMLDoc.loadXML(Node.nodeValue);

or any combination of the above. It all fails due to the string length limitation.

Any idea how I could solve the problem?

Comments

  • ara3nara3n Member Posts: 9,256
    Hello.

    You need to use
    IXMLDOMText interface works also with attributes.
    msXmlDomText := XMLDoc.selectSingleNode('Envelope/Body/GetTransactionResponse/transaction');
    
    msXmlDomText.substringData(startpos,Length);
    

    Remove the <![CData[ and read the reason into a stream.

    Use another xmldom document to load from the new stream.

    Then you can use selectSingleNode('Widextransaction/transactiondate'); to extract specific nodes.


    The Cdata element makes it basically free form data and anything can be put in it. So the DOM cannot parse it but stores it in nodetext. That's why you need to extract it and put into another DOM document sins it's valid xml data.


    As far as COM interface limitation. It's a painfully limitation that I'm running constantly against in every other integration.

    MS Please increase it in the next SP1. !!!!!!!!!!!!!!!!!!!!! [-o<
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • JAKAJAKA Member Posts: 18
    Hello!
    ara3n wrote:
    ...
    msXmlDomText.substringData(startpos,Length);
    ...
    Remove the <![CData[ and read the reason into a stream.
    ...

    This sounds so easy but I still can't get it. :(

    Not like this:
    msXmlDomText.CREATEINSTREAM(TestStream);


    Could you give me a simple example how to read text into a stream?
  • ta5ta5 Member Posts: 1,164
    Maybe a namespace problem.
    Try to use a sample xml file from msdn or w3c schools and test your code against this "clean" files. If everything works allright you can get back to the real file.
    I know this is the slow way, but you get more insights of the problem.

    Btw: Can you get the Text from "GetTransactionResult"?

    Hope this helps
    Thomas
  • SkeeveSkeeve Member Posts: 33
    I was able to convince the client to change the web service so the actual < > signs are sent and to remove the CDATA. With these 2 changes, I am now receiving a well-formed document that I can simply process \:D/
  • ara3nara3n Member Posts: 9,256
    That's great news.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.