Searching XML String in Javascript/JQuery -


i need way search through xml string , return array containing "record" elements meet multiple search criteria.

the structure this:

  <record>      <project_name>deploy document management</project_name>      <project_phase>design</porject_phase>      <status>not started</status>      <priority>medium</priority>   </record>   <record>      <project_name>do else</project_name>      <project_phase>design</porject_phase>      <status>not started</status>      <priority>medium</priority>      </record> 

if wanted return array of "records" status="not started" , priority = "medium".... how using javascript or jquery?

to clear, need whole record each record matches criteria.

thanks in advance.

a start parse xml, example jquery.parsexml()

you can acces dom of returned document would

example:

var xml = '<xml><record><project_name>deploy document management</project_name><project_phase>design</project_phase><status>not started</status><priority>medium</priority></record><record><project_name>do else</project_name><project_phase>design</project_phase><status>not started</status><priority>low</priority></record></xml>'    var xmldoc = $.parsexml(xml)  var $xml = $(xmldoc)  var $records = $xml.find("record").filter(function() {    return $(this).find("status").text() == "not started" &&       $(this).find("priority").text() == "medium"  });    // $records holds elements array, cold texts this:  var records = []  $records.each(function() {    // thing    records.push($(this).text())  })    document.write(json.stringify(records))
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

note have typo in original xml project_phase


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -