I have a big text problem. I’m importing some XML files and part of these are some nodes which are to be imported into a BigText variables. But when I’m running the system then I’m getting this error:
The length of the text string exceeds the size of the string buffer.
The code I’m using looks more or less like this:
Node := Element.selectSingleNode(NodeName);
IF ISCLEAR(Node) THEN
ERROR(Text002,NodeName);
ELSE BEGIN
CLEAR(BigText);
BigText.ADDTEXT(Node.text);
END;
The error occurs on the ADDTEXT statement. The BigText variable is (ofcourse) of the BigText variable type. Node is ‘Microsoft XML, v6.0’.IXMLDOMNode.
Isn’t it possible to import a bigtext node from an XML file into NAV?
I think your issue isn’t in ADDTEXT function but in Node.Text, because when you execute Node.Text your converting it first to TEXT, as is limited to 1024 chars.
Save your xml to a blob, and use the blob to stream to your bigtext:
TempBlob.Blob.CREATEOUTSTREAM(OutStream);
Node.save(OutStream);
TempBlob.Blob.CREATEINSTREAM(InStream);
BigText.READ(InStream);
I think there isn’t a clean solution for your issue. You could pass your node has a reference to a XML document and save that node to a stream. But you aren’t parsing the text inside, you are saving the all the node.
A workaround, could be saving that node has an XML document, and parsing it using an xmport, since it can handle bigtext on a clean way.
My advice would be to use a node type IXMLDOMText. This node has convenient methods for text data manipulation. In your case Iwould use substringData in a loop, while transporting text in chunks of 1024bytes. Do you require a code example?
Thanks, looks like we are going in the right direction. Except that The only remaining problem is how to get to the TextNode. Whenever I try to assign the regular DOMNode to the IXMLDomText node then it fails (Invalid assignment. It is not possible to assign a IXMLDOMElement to a IXMLDOMText).
As to Nuno’s suggestion on using an XMLPort, then I would rather try to find another way to do, as that would really require a lot of extra code.
You can not assign an IXMLDOMElement to a IXMLDOMText, quite true. DOMNode is not a text node itself. Text nodes are sort-of virtual nodes that are implicitly attached to element (and some other) types of nodes. That is why you need to assign the child node. If DOMNode had multiple children, you would have to retrieve the node list (childNodes) and loop through until you found the one (and only one) of the nodeType text.
To sum it up: DOMNode is your element. DOMNode.firstChild is its text node, assuming there are no “real” children.
Ok, so it would seem firstChild is not a text node. Does your node of interest have more children? Attributes, elements? In this case you will have to use a node list, as I also explained.
Actually, contrary to what I stated initially, the number of text nodes belonging to a single parent node is not limited to one but unlimited. That considered, you may actually have to look not only for the first text child node, but in fact for all of them.
An additional advice if I may. You have basically two approaches to evaluating children. The first I already mentioned. You retrieve a nodelist with .childNodes and use a FOR statement to go through the indexed collection.
The second approach is to start with .firstChild as in my example and then cycle through its siblings using the .nextSibling property.