1

My XML looks like this:

<jobs>
  <job>
    <title>Engineer - System Planning</title>
    <url>http://my.jobs/0629cdc680d04cf3bcd711a1c0b69836321</url>
    <company>Iberdrola USA</company>
    <location>Augusta, ME</location>
    <dateacquired>2013-3-22 6:24 PM</dateacquired>
    <jvid>0629cdc680d04cf3bcd711a1c0b69836321</jvid>
  </job>
  <job>
    <title>Engineer - Hydro</title>
    <url>http://my.jobs/61cccbfba50c4f93a5169aafc13c82b2321</url>
    <company>Iberdrola USA</company>
    <location>Rochester, NY</location>
    <dateacquired>2013-7-5 8:33 PM</dateacquired>
    <jvid>61cccbfba50c4f93a5169aafc13c82b2321</jvid>
  </job>
</jobs>

And I am wanting to use the XPath.js NPM Module (https://www.npmjs.org/package/xpath.js). but I am just not sure how to loop through each job in the XML document using that module

1
  • The readme for xpathjs contains plenty of good examples for that. Are you asking how to use npm packages in meteor or are you asking ho to construct an xpath query? Commented Mar 19, 2014 at 23:06

1 Answer 1

4

From the first example in the xpath.js documentation, with an XPath expression like //job you'll get a node-set:

var nodes = select(doc, "//job");

which you can loop using regular JavaScript, since it's an array. You can then pass each node as a parameter in another XPath expression and obtain the data inside the other nodes:

for (i = 0; i < nodes.length; i++) {
    var title   = select(nodes[i], "title/text()")[0].data;
    var url     = select(nodes[i], "url/text()")[0].data;
    var company = select(nodes[i], "company/text()")[0].data;
    ...
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much! I had looked at the documentation for so long that I just was having a hard time discerning it all

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.