Categories: jQuery

jQuery Makes Parsing XML Easy

Share

jQuery.parseXML uses native parsing function of the browser to create a valid XML document.

After that this document can then be passed to jQuery for creating a typical jQuery object which can be traversed and manipulated then.

This is a easy technique of parsing JSON with jQuery and thought i’d pick this up and show you how to parse XML. It is available from jQuery 1.5 version.

Here is the XML code for the purpose of the demo.

var xml = "<note><heading>Sample Heading</heading><body>Hi! Is this the body you are looking for?</body></note>";
xmlDoc = $.parseXML( xml );
$xml = $( xmlDoc );
$body = $xml.find( "body" );
console.log($body.text());

You will get the result: Hi! Is this the body you are looking for?

Get more details from jQuery reference.

Recent Posts

The Rise of NFTs: Exploring the Impact of Non-Fungible Tokens on the Digital Economy

NFTs, or Non-Fungible Tokens, are revolutionizing the digital economy. These unique digital assets, authenticated through…

4 hours ago

Unveiling the Truth: Is the Spread of Sinus Infections a Myth or Reality?

Sinus infections, impacting approximately 31 million Americans each year, represent a significant health concern stemming…

1 day ago

Best Exercises To Reduce Weight & Keep You Stronger & Fitter!

No doubt that balanced weight is the key to wellness. So, when it comes to…

1 day ago

ARTIFICIAL INTELLIGENCE: Advantages And Disadvantages? Everything You Need to Know

Pros And Cons Of AI: Artificial Intelligence directly translates to conceptualizing and building machines that…

2 days ago

Four common mistakes when picking an internet provider

We all live on the internet; we use it for everything. Thus, when it comes…

2 days ago

What Is Commonly Misdiagnosed as Pink Eye: Understanding Eye Conditions and Their Symptoms

Introduction: Pink eye, or conjunctivitis, is a common eye condition characterized by redness and inflammation…

2 days ago