10-12-2016 05:56 AM - edited 03-14-2019 04:39 PM
I want to get these date from one XML file. My script works well, except one part doesn't work. I can not write correct XML PATH.
So, every time. I got null from this XML file.
Thanks in advance
<?xml version="1.0" encoding="ISO-8859-1"?>
<Holidays>
<Holiday>12/10/16</Holiday>
<Holiday>1/20/14</Holiday>
<Holiday>4/26/14</Holiday>
<Holiday>7/4/14</Holiday>
<Holiday>9/1/14</Holiday>
<Holiday>10/17/14</Holiday>
<Holiday>11/27/14</Holiday>
<Holiday>12/10/16</Holiday>
<Holiday>10/12/16</Holiday>
<Holiday>"10/12/16"</Holiday>
<Holiday>"12/10/16"</Holiday>
</Holidays>
Solved! Go to Solution.
10-12-2016 07:48 AM
Don't look at Cisco's documentation for anything to do with XPath. The W3Schools Tutorial is how I figured XPath out.
In your case, the XPath query is as simple as "/Holidays/Holiday[1]" to get 12/10/16; "/Holidays/Holiday[2]" to get 1/20/14, etc.
Since you have an unpredictable quantity of <Holiday> elements you would want to wrap the logic within a Do While loop. The iterator variable would replace the number, making your XPath query (in concatenated String format) "/Holidays/Holiday[" +
10-12-2016 07:21 PM
Agreed with Jonathan below on the XPath comments.
I'd take a punt you're possibly wanting to check the holidays xml file to see if today is a holiday. I'd originally done a loop to check each holiday, but ended up changing the format of my xml to allow me to do a single xpath lookup.
XML format looks like:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- NO LEADING ZEROES IN DATE NUMBERS !!!! -->
<!-- DD/MM/YYYY Format -->
<!-- HolidaysObserved: -->
<!-- NewYearsDay, AustraliaDay, EightHoursDay -->
<Holidays>
<Holiday Date="1/1/2016">NewYearsDay</Holiday>
<Holiday Date="26/1/2016">AustraliaDay</Holiday>
<Holiday Date="14/3/2016">EightHoursDay</Holiday>
</Holidays>
I then use the following script code to query my xml:
Couple of things to note:
Hope this assists.
10-12-2016 07:48 AM
Don't look at Cisco's documentation for anything to do with XPath. The W3Schools Tutorial is how I figured XPath out.
In your case, the XPath query is as simple as "/Holidays/Holiday[1]" to get 12/10/16; "/Holidays/Holiday[2]" to get 1/20/14, etc.
Since you have an unpredictable quantity of <Holiday> elements you would want to wrap the logic within a Do While loop. The iterator variable would replace the number, making your XPath query (in concatenated String format) "/Holidays/Holiday[" +
10-12-2016 07:21 PM
Agreed with Jonathan below on the XPath comments.
I'd take a punt you're possibly wanting to check the holidays xml file to see if today is a holiday. I'd originally done a loop to check each holiday, but ended up changing the format of my xml to allow me to do a single xpath lookup.
XML format looks like:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- NO LEADING ZEROES IN DATE NUMBERS !!!! -->
<!-- DD/MM/YYYY Format -->
<!-- HolidaysObserved: -->
<!-- NewYearsDay, AustraliaDay, EightHoursDay -->
<Holidays>
<Holiday Date="1/1/2016">NewYearsDay</Holiday>
<Holiday Date="26/1/2016">AustraliaDay</Holiday>
<Holiday Date="14/3/2016">EightHoursDay</Holiday>
</Holidays>
I then use the following script code to query my xml:
Couple of things to note:
Hope this assists.
10-12-2016 11:24 PM
Thanks for Nathan and Jonathan! Your answers are really helped a lot.
I noticed that your names are very closed.
and, I figured out other way myself which is very close to Nathan's method.
XML PATH part: "//Holiday[text()='"+todaysDate+"']"
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide