2

I'm trying to use JQuery to parse XML that way I can post content from an RSS Feed to my site. However, I'm stuck.I'm not sure how to load a XML file with JQuery. I've created an example at the link below. Thanks

http://jsfiddle.net/deadendstreet/DytGM/1/

var xml;
$.get("http://straight2jackie.blogspot.com//feeds/posts/default?alt=rss", function(data) {
    xml = data;
});,
    xmlDoc = $.parseXML( xml ),
    $xml = $( xmlDoc ),
    $title = $xml.find( "title" );

/* append "RSS Title" to #someElement */
$( "#someElement" ).append( $title.text() );

/* change the title to "XML Title" */
$title.text( "XML Title" );

/* append "XML Title" to #anotherElement */
$( "#anotherElement" ).append( $title.text() );
1
  • can you post a example of your xml ? Commented Mar 29, 2013 at 15:08

2 Answers 2

3

If you call $.get with the dataType parameter (i.e. dataType:'xml') you automatically have xml parsing.

By the way, I think here you're facing another problem: you can't load ajax resources from external (sub)domains: check here.

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

Comments

0

You can try the jQuery.parseXML() and a code something like :

<script>
    var xml = "<rss version='2.0'><channel><title>RSS Title</title></channel></rss>",
    xmlDoc = $.parseXML( xml ),
    $xml = $( xmlDoc ),
    $title = $xml.find( "title" );
    /* append "RSS Title" to #someElement */
    $( "#someElement" ).append( $title.text() );
    /* change the title to "XML Title" */
    $title.text( "XML Title" );
    /* append "XML Title" to #anotherElement */
    $( "#anotherElement" ).append( $title.text() );
</script>

1 Comment

Thanks actually what I started with. I just don't understand how to update the var xml to link to an actual file. In that example, the xml is part of the document. Is it possible to link to a file, say in a folder on my server?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.