Options

contents of an XML file

cedriccedric Member Posts: 8
Hi,

when using the XMLDOM object model for handling XML files I receive the error 'text of text string too long for...' when calling the XMLDoc.xml method. I need the complete content of the XML file...
Apparently the BSTR automation datatype is used internally and this can only handle upto 250 chars.
Does anyone has a suggestion how to overcome this problem ?
Thx

Comments

  • Options
    DenSterDenSter Member Posts: 8,304
    Depends on what you want to do with that text. I usually browse an XML document node by node to get the values, so I've never had to use the entire content.

    Have you tried using a BigText datatype?
  • Options
    Dennis_DecoeneDennis_Decoene Member Posts: 123
    Why not use an XMLPort?
  • Options
    cedriccedric Member Posts: 8
    To answer DenSter: I not only want the content but also the structure of the document.
    To answer Dennis: we use Navision 3.70 (No XMLPort)


    tempVar : Text[1024]
    XMLDoc : Automation 'Microsoft XML, v4.0'.DOMDocument

    tempVar := XMLDoc.xml // throws the error
    but also
    MESSAGE(XMLDoc.xml)//it is within the .xml method that the BSTR datatype is used
  • Options
    DenSterDenSter Member Posts: 8,304
    The BSTR is not an internal variable, it is the return value of the MSDOM Object's xml method, and it represents a text variable of unlimited length. You get the error because the Text variable in Navision can only hold 1024 characters, so each time you try to put more in it, it raises an error.

    Maybe you could share exactly what you need to do, and we can find a solution for you. I don't believe BigText is a datatype in 3.70, so you may have to find something another approach. Because I don't know what you want to do, I can't make any suggestions.
  • Options
    cedriccedric Member Posts: 8
    First I want to mention that Im not so sure BSTR is unlimited...
    I did a character count on the incoming XML message, with < 250 charactes the XMLDOC.xml method succeeds, with > 250 it fails.

    This is what it's for:

    XMLDoc.save('c:\temp.xml') -> saves an xml file but WITHOUT the declaration section (<?xml version="1.0" encoding="ISO-8859-1" ?>)

    so I started this approach
    XMLContents := '<?xml version="1.0" encoding="ISO-8859-1" ?>'+ XMLDoc.xml;
    and write the XMLDoc to a file.

    BTW: Thanks for helping me out on this...
  • Options
    DenSterDenSter Member Posts: 8,304
    I am absolutely positive that the MSDOM object can hold more than 250 characters. I have programmed a sales order xml import for enormous xml documents, so a limitation to the BSTR return variable should not the problem aruond 250 characters. I am wondering about the variable you are using to catch the text.

    I haven't tried creating a declaration node, I am surprised that MSDOM.Save doesn't save it. Have you tried creating a new MSDOM object, write the declaration using the MSDOM object model (Create a new child node or something) and then adding the other MSDOM.RootNode to your new MSDOM object. I'd have to try this myself, so I don't know if that'll help.
  • Options
    cedriccedric Member Posts: 8
    Daniel,
    even the MESSAGE(XMLDoc.xml) statement throw the error. Sure the XML file can contain more than 250 chars but it is the .xml method on the XMLDOM that returns the exception.
  • Options
    SaalekSaalek Member Posts: 181
    Hi
    If you are creating the XML file, the first thing you must do is that.

    Name DataType Subtype Length
    XMLNode Automation 'Microsoft XML, v3.0'.IXMLDOMNode
    XMLProccesingInst Automation 'Microsoft XML, v3.0'.IXMLDOMProcessingInstruction

    XMLProccesingInst:=XMLDoc.createProcessingInstruction('xml','version="1.0" encoding="iso-8859-1"');
    XMLNode := XMLDoc.appendChild(XMLProccesingInst);
    XMLNode:=XMLDoc.createElement('ROOT');
    ...

    If you receive this XML and you must add Processing instruction line before all, why don't use 2 File variable, you add this line in one of them and after you add all the lines copying by the other file ??

    By
  • Options
    cedriccedric Member Posts: 8
    Thanks !
    IXMLDOMProcessingInstruction is just what I was looking for !
  • Options
    DenSterDenSter Member Posts: 8,304
    Thanks Saalek, that is very useful information =D>. I knew it was in the object model somewhere, just didn't know exactly which method to use.
  • Options
    SaalekSaalek Member Posts: 181
    Hi
    You're welcome :oops: :oops: :oops:

    I'm hard working with XML integrating Navision with Web Servers (No User Portal, no Commerce portal,...) only ASP, VBScript and XML Files.

    A Strange thing: To trate an XML file with Navision, is not necesary to have the Processing Instruction. You can directly access to the Root Node

    By

    P.D.: Excuse me if my English isn't very good, but I'm studing English since 2004.
  • Options
    DenSterDenSter Member Posts: 8,304
    Your English is very good, at least I think I understand everything you say :).
Sign In or Register to comment.