views:

946

answers:

2

hi, I am having an issue with parsing XML with JQuery when there is a node with an option node

<preferences><dashboard>
<report id="si_pg_vw" order="0">
  <header>
    <data>
      <option type="reportname" value="Page View"/>
    </data>
  </header>
</report>

the following code in firebug returns no children

$reportElement.find("data")[0]

however if I change option to any other value ("option2", "test" etc) then the line above returns one child which is correct.

Am I mising something or is there a bug?

Thanks

John

A: 

Perhaps this has to do with the HTML option tag need to be a child of the select tag.

Make sure that the content-type of the response is 'text/xml'. This will probably instruct jQuery to parse the response as xml and not html, thus properly recognizing the option tag.

kgiannakakis
Unfortunately this is coming from the server, and other applications depend on this node being "option".
JD
See my edited answer. I believe you need to set the content type header.
kgiannakakis
A: 
$reportElement.find("data")[0]

will not work. Try

$reportElement.find("data:first")

OR

$reportElement.find("data:eq(0)")

etc

Also, you are not closing 'dashboard' and 'preferences' in your example.

This is the complete example;

var myXML = <preferences>
              <dashboard>
                 <report id="si_pg_vw" order="0">
                    <header>
                      <data>
                         <option type="reportname" value="Page View"/>
                      </data>
                    </header>
                </report>
             </dashboard>
           </preferences>

myXML = jQuery(myXML);
myXML.find('data option:first');
//OR
myXML.find('data option:eq(0)');
//OR
myXML.find('data option').each(function(){ window.console.log(this) });

etc

AamirAfridi.com