0

Why do I get Invalid XML when I parse with jquery xml

$(document).ready(function() {
    var xml = '<?php echo XML_CONFIGS . '/feed_config.xml' ?>';
    $("#sql_config").click(function(e) {
     e.preventDefault();  
     xmlDoc = $.parseXML(xml ),
     $xml = $( xmlDoc ),
     $feed = $xml.find( "feed[id = 4]" );

     console.log($feed);
        var data = $('#sql').serialize();              
    }); 

The hosted xml http://ui.kakuki.de/feed_config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <element>
        <feed id=" 4 ">
            <title>My Feed</title>
            <table>my_table</table>
            <link>http://testsite.com/export/export?myFeed=13&amp;myFormat=134251570</link>
            <feed_type>XML</feed_type>
        </feed>
        <query/>
    </element>
</config>
8
  • The XML you provided is valid. I guess, it differs from the one, stored in the xml variable. Commented Aug 15, 2013 at 7:58
  • I've been validating the hole xml and seems to be okay Commented Aug 15, 2013 at 8:00
  • Debug your code to see, if the value stored in xml variable is valid XML document. Commented Aug 15, 2013 at 8:02
  • Host the xml and share the link for that. It will be easier for us to see what's going wrong ... Commented Aug 15, 2013 at 8:09
  • 2
    All seems valid to me but your $xml.find will return an empty array as your id isn't 4 its " 4 " eg. "feed[id=\"4\"]" Commented Aug 15, 2013 at 8:13

1 Answer 1

1

The $.parseXML(xml) and XML all seems fine and loads for me in all browsers I have tested with.

However your $xml.find will return an empty array as your id is incorrect.

Your id isn't 4 its " 4 " so your find should be $xml.find("feed[id=\" 4 \"]")

Glad I could help.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.