Reputation: 16627
I would like to perform a regex match on some XML content in JavaScript.
Sangeeth
Upvotes: 0
Views: 4996
Reputation: 22115
Regex is generally a bad idea for parsing XML.
Here is a solution using jQuery : XML parsing of a variable string in JavaScript
Upvotes: 1
Reputation: 944443
How do we store XML contents in a JavaScript variable?
That depends on where you are getting the XML from. If you get fetching it over HTTP, then XMLHttpRequest will create an XML object for you (in obj.responseXML
). If you are embedded the markup in a string then I believe DOMParser is fairly well supported (and pairs with MSXML.DOMDocument in Microsoft-land)
What are the effective ways to retrieve the XML content from a JavaScript variable
DOM and XPath
to perform a regex match?
I hope you mean "to perform a regex match on text extracted from the XML". Regular expressions are a very poor tool for parsing XML.
Upvotes: 0