We help IT Professionals succeed at work.

maximum size of a javascript variable

wrynn
wrynn asked
on
466 Views
Last Modified: 2012-05-05
im putting an xmldocument into a variable and for some reason it is splitting it into 2 nodes instead of one.  and the second node isnt even a complete node it is likeL

ple/></end>


and the first node is the beginning of the xmldocument but at the end the last part is cut off and continues in the second node. so u have childnodes[0] and childnodes[1] and its split up isntead of the entire in just 1 node like i want it

is it because its running out of space and has to split it up?  im confused
Comment
Watch Question

Top Expert 2007

Commented:
From your example, I sure can't say...
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
it seems strange that when i do alert(rootNode.childNodes[0].data) it prints out the 99% of the document and then 1% into childNodes[1].data.  shouldnt there be many more nodes than that? like one node for each element in the xml tree?  i wish it would do that.
I don't understand fully what you are trying to do.

To my knowledge, node.data is not a standard property of XML DOM Node. To get the text of a textnode, you should use node.nodeValue.

Also, childNodes property contains only the immediate childs of the node. To get all nodes, deeper in the XML structure, you should use some recursive function or similar method. you can easily get all ELEMENTS of a document by calling document.getElementsByTagName("*"), but text nodes are not included.

So, for a document.childNodes[0] will usually return the "document element"/"root node", or document type declaration node. document.documentElement is a more reliable way to get the root node.

Maybe we can help if you try to be more specific on what you are trying to accomplish.

Author

Commented:
here's what the xml looks like:

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
   <env:Header/>
   <env:Body>
      <ns1:Response xmlns:ns1="http://blahblah/blah" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <ns1:result><![CDATA[<RESULT>....



so  do u think i need to maybe convert it to a string and then just cut out the xml i need starting with <result> and ending with </result> and then convert that back to an xml object and THEN try using getElementsByTagName?  because right now getelementsbytagname isnt working properly
oh I see, the XML you have contains other XML document as textnode (actually CDATA section, but it's the same thing)

I think the easiest would be to first get a handle of the result node;

var resultnode = document.getElementsByTagName("ns1:result")[0];

if this does not work, you might also try this:

var resultnode = document.getElementsByTagNameNS("http://blahblah/blah" "result")[0];

Then, the most fail-safe method (regarding the splitted text/cdata nodes) would be to loop the childNodes and collect the textual data to one string:

var resultstring = [];
for (var i = 0; i < result.childNodes.length; i++) {
   resultstring.push(result.childNodes[i].nodeValue);
}
resultstring = resultstring.join("");

Now you should have an string containing XML, that looks like "<RESULT>.........</RESULT>".

You can now parse that to a different document if you want to get a DOM handle of that result. In firefox you do it like this:

var parser=new DOMParser();
var resultdoc=parser.parseFromString(resultstring,"text/xml");


This may sound complex, but it is because of the awkwardly formatted/designed soap response. Using namespaces it would be trivial to have the result rendered as a real childnode tree of the soap response Body, instead of embedding another document as CDATA text and the need to parse the response two times.
Sorry, this code section:

for (var i = 0; i < result.childNodes.length; i++) {
   resultstring.push(result.childNodes[i].nodeValue);
}

Should look like this:

for (var i = 0; i < resultnode.childNodes.length; i++) {
   resultstring.push(resultnode.childNodes[i].nodeValue);
}

Author

Commented:
is document.getElementsByTagNameNS() and the rest of your code tested in ie6?

Author

Commented:
if not could you please provide examples for that browser as well? thanks
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.