0

this is a part of xml:-

<products>
  <product_id value="1">
    <tab_id value="351">
      <tab_name value="test1"/>
      <date value="2013\05\10 12:30:00" />
    </tab_id>
  </product_id>
  <product_id value="2">
    <tab_id value="352">
      <tab_name value="test2"/>
      <date value="2013\05\12 12:00:00" />
    </tab_id>
  </product_id>
</products>

i have following string in one variable:-

var result_date="2013\05\10,2013\05\11,2013\05\12,2013\05\13";

here i want to check result_date every date with the xml file element date.
using javascript and xpath.
if result_date is match in xml date then return there product_id
i dont know how to check yyyy/mm/dd hh:mm:ss to yyyy/mm/dd
expected output:-

 1,2

this both are product_id IN MY xml file.
help me out with this.
thansk

1
  • 1
    Since JavaScript has no native XPath support: What XPath library are you using? Commented May 4, 2013 at 6:43

1 Answer 1

2

The xpaht expression you are looking for should be something like:

var path="//product_id[contains('" + result_date+ "',substring-before(date/@value ,' '))]";

Searching any product_id where the substring-before the blank in date is part of your variable result_date.

Most browser support "evaluate" (but not IE).

var nodes=xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null);
var result=nodes.iterateNext();
while (result)
  {
  document.write(result.attributes.value.nodeValue);

  document.write("<br>");
  result=nodes.iterateNext();
  }

If your "result_date" is a const string. You have to be aware of escaping.

var result_date='2013\\05\\10,2013\\05\\11,2013\\05\\12,2013\\05\\13';
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.