views:

128

answers:

2

Hi, This is a fairly simple problem but I can't find a solution. I write some xml to a hidden div on tha page and i read it later on. The problem is that some quotes are being removed when writing to the div and because of this I can't load the use the xml in IE using LoadXML

this is the XML

<parameters id='XXX'>
<product_id value='YYY'/>
<report_id value='ZZZ'/>
<list>
 <filter_id value='AAA'/>
</list>
<date_begin value='BBB'/>
<date_end value='CCC'/>
<timeframe_id value='DDD'/>
<chart_id value='EEE'/>

I have used alot of different methods but none seem to work, I am trying to use JQUERY as much as possible to prevent cross browser issues, but any solution will do.

I append the xml, in a string variable paramString, above using

var parametersDiv = "<div id='" + reportDivId + "_params' style='visibility: hidden; display: none'>" + paramString + "</div>";

and it goes in fine.

however when I try to retrieve it the quotes around the XXX are removed in IE. Thus I can't load it using loadXML(). I could hack a solution but i'd like to do it correctly.

Any solutions would be helpful, i've wasted nearly a day on this already.

Thanks

JD

+1  A: 

Try using double quotes and see if that does the job.

If not, another solution to your problem might be to get the XML trough a XMLHttpRequest (Ajax).

jQuery.ajax({
  url: 'yourUrlThatReturnsXML',
  dataType: 'xml',
  success: function (data, textStatus) {
   $(data); // Your XML
  }
});
Christian Toma
I'm not sure double quotes would do anything as it is only the first parameters that the error is with.What's happening is that I have a large XML request coming back through ajax. i am parsing that xml and placing certain section in hidden divs around the page, so that the next time i want to make a request I can piggy back on the saved values.
JD
Try saving the XML as objects in variables. var globalXML=$(data);
Christian Toma
unforunately the page is completely dynamic and I'm not sure if I can have dynamic variable names in javascript. however I could create a hashtable and store names along with the xml values. I'll try that.
JD
That's what I was going to suggest an array.
Christian Toma
yes this is working now, thanks for your solution
JD
A: 

How are you inserting these hidden divs into the page? Presumably you are using innerHTML (given that you have a string), but this means that it is being passed through IE's HTML parser. This will turn it into (invalid) HTML, and when you try to retrieve it you will see the effect you describe of attributes being unquoted (and probably other side effects which you happen not to have encountered... yet).

Your best bet is to save a reference to the returned XML document (not a string serialisation thereof) in a variable.

NickFitz
yes this is working now, thanks for your solution
JD