Parsing multiple xml files with Jquery

urbestpron

New Member
I have multiple xml files that I am trying to parse using JQuery. So far, I've only found success by parsing each file individually. I'm new at this and my code is very long and repetitive. I'd appreciate any help scaling it down. Here is my js:\[code\]$.ajax({ type: "GET", url: "docs/doc1.xml", dataType: "xml", success: parseXml1});$.ajax({ type: "GET", url: "docs/doc2.xml", dataType: "xml", success: parseXml2});$.ajax({ type: "GET", url: "docs/doc3.xml", dataType: "xml", success: parseXml3});function parseXml1(xml){ var gen = $(xml).find("subsystem").eq(0); var title = gen.find("title").text(); var text = gen.find("text").text(); $("#Title01").html(title); $("#Text01").html(text);};function parseXml2(xml){ var gen = $(xml).find("subsystem").eq(0); var title = gen.find("title").text(); var text = gen.find("text").text(); $("#Title02").html(title); $("#Text02").html(text); var sys = $(xml).find("subsystem").eq(1); var title = sys.find("title").text(); var text = sys.find("text").text(); $("#Title02-1").html(title); $("#Text02-1").html(text);};function parseXml3(xml){ var gen = $(xml).find("subsystem").eq(0); var title = gen.find("title").text(); var text = gen.find("text").text(); $("#Title03").html(title); $("#Text03").html(text); var sys = $(xml).find("subsystem").eq(1); var title = sys.find("title").text(); var text = sys.find("text").text(); $("#Title03-1").html(title); $("#Text03-1").html(text);};\[/code\]And my xml is set up as follows:\[code\]<root> <subsystem>This is information 1</subsystem> <subsystem>This is information 2</subsystem></root>\[/code\]So I have multiple nodes with no attributes that I am trying to access one by one within each xml file. Then, I am trying to put that text into a div on my HTML page. There has to be a better way to do this.
 
Back
Top