Get the latest date in the Xpath1.0 - xpath

I have a requirement where I need the latest date from the XML below. In Xpath 2.0, there is function called max(). But am using Xpath1.0.
<Info><Date>2014-04-21</Date></Info><Info><Date>2014-05-05</Date></Info><Info><Date>2014-04-28</Date></Info>
Expected Output: 05/05/2014(dd/mm/yyyy)
Any inputs ??

Actually there is small change in my xml. The following is my XML(extra parent node is added).
<CustomContent>
<Info>
<Name>abc</Name>
<Date>2014-04-21</Date>
</Info>
<Info>
<Name>def</Name>
<Date>2014-05-05</Date>
</Info>
<Info>
<Name>ghi</Name>
<Date>2014-04-28</Date>
</Info>
</CustomContent>
Now here is the Xpath to find the max date for the above XML.
//CustomContent/Info/Date[not(text() <= preceding::Date/text()) and not(text() <=following::Date/text
())]/text()
Thanks everyone :)

Related

In xml file, append an attribute to node element if that attribute not exist using shell script

I have the below requirement on xml file using Shell script
Standalone.xml file
<?xml version='1.0' encoding='UTF-8'?>
<server xmlns="urn:jboss:domain:11.0">
<profile>
<subsystem xmlns="urn:jboss:domain:deployment-scanner:2.0">
<deployment-scanner path="deployments" relative-to="jboss.server.base.dir" scan-enabled="false" scan-interval="5000" deployment-timeout="600"/>
</subsystem>
...........Other subsystems tags.......
<server>
Would like to check node contains the attribute "deployment-timeout" or not
if exist read the value then check
if the value is <900
update the value to 900
else
Leave as it is
else
Append attribute with value i.e deployment-timeout="900" to node <deployment-scanner> at the end like this
*<deployment-scanner path="deployments" relative-to="jboss.server.base.dir" scan-enabled="false" scan-interval="5000" deployment-timeout="900"/>*
Please help me...
advance thanks

Identify all xml files with specific format

I am trying to find xmls which are not having valid data and not process them. For example , below is a correct xml with all the data available which needs to be processes
(Loop Xpath used to read the data from xml files- Invoicing/Invoice/Serials/SerialNumber):
<?xml version='1.0' encoding='UTF-8'?>
<Invoicing>
<Invoice>
<VendorName>Contec</VendorName>
<InvoicePeriod>May</InvoicePeriod>
<InvoiceDt>2019-05-11</InvoiceDt>
<InvoiceNo>20190511</InvoiceNo>
<Serials>
<SerialNumber>
<TestLoc>HNMA01</TestLoc>
<EISSerial>PKQPLPXJC</EISSerial>
<ComcastModel>PX022ANC</ComcastModel>
<RMANo />
<ReceiptDt>05/09/2019</ReceiptDt>
<RepairDt>05/11/2019</RepairDt>
<Parts>
<Part>
<PartType>Cosmetic</PartType>
<PartId>SERVICEBUFFING</PartId>
<PartDescr>BUFF SERVC</PartDescr>
<ActionCd>RA003</ActionCd>
<FSC>FS005</FSC>
</Part>
</Parts>
</SerialNumber>
</Serials>
</Invoice>
</Invoicing>
I also get XML which are in below format,
<?xml version="1.0" encoding="UTF-8"?>
<Invoicing>
<Invoice>
<VendorName>Contec</VendorName>
<InvoicePeriod>May</InvoicePeriod>
<InvoiceDt>2017-05-01</InvoiceDt>
<InvoiceNo>20170501</InvoiceNo>
<Serials></Serials>
</Invoice>
</Invoicing>
The above xml , even though being valid is not correct..I want to identify the xmls which are in the second format without the complete data and move them into a error folder.
Thanks,
Kavin
Solution to this question is as follows :
I was able to achieve what i wanted with the solution provided by #EdMorton.
grep -L '<SerialNumber>' *.xml
But i wanted to get this done using a xml parser.
count=$(xmllint --xpath "count(//SerialNumber)" "$xml")
When the count is zero i have implemented my logic.
Thanks for all the help.

What are the steps used to generate the Erlangen map?

I have imported a .osm file from QGIS and then I used sumo-0.22.0 to generate .net.xml ; .poly.xml and .rou.xml files since I use Veins-4a2. When I simulated the scenario of Veins, the application layer of RSU did not executed. So I need to understand how the Erlangen files was done because the problem is my scenario (my files).
Can you tell me please what are the steps used to generated the .net.xml ; .poly.xml and .rou.xml?
You can always have a look at the xml files with a text editor or even a simple pager. Almost all sumo tools write a header to their output files which tells the version, the options and the date of creation. In case of the erlangen network this says:
<!-- generated on Wed Nov 30 12:18:33 2011 by SUMO netconvert Version 0.13.1
<?xml version="1.0" encoding="iso-8859-1"?>
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.sf.net/xsd/netconvertConfiguration.xsd">
<input>
<type-files value="erlangen.edgetypes.xml"/>
<osm-files value="erlangen.osm"/>
</input>
<output>
<output-file value="erlangen.net.xml"/>
</output>
<projection>
<proj.utm value="true"/>
</projection>
<edge_removal>
<remove-edges.isolated value="true"/>
</edge_removal>
<processing>
<osm.discard-tls value="true"/>
<no-turnarounds value="false"/>
<offset.disable-normalization value="true"/>
<roundabouts.guess value="true"/>
<junctions.join value="true"/>
</processing>
</configuration>
-->
which mentions all the information asked for (hopefully). The route file has no such header, so I suppose, it is handmade.

Can I write inside a xml node using Ruby/Builder?

There's my code:
require 'builder'
def initXML(builder)
builder.instruct!
builder.results(:result => 'result'){}
end
def writeXML(builder,name,hello)
builder.test(:name => name){
builder.hello hello
}
end
builder = Builder::XmlMarkup.new(:target=> STDOUT, :indent=>4)
initXML(builder)
writeXML(builder,'name1','hello1')
writeXML(builder,'name2','hello2')
Executing that I get this XML:
<?xml version="1.0" encoding="UTF-8"?>
<results result="result">
</results>
<test name="name1">
<hello>hello1</hello>
</test>
<test name="name2">
<hello>hello2</hello>
</test>
But I want the </results> end tag at the end of file. There's a way to write inside the <results> node? Or move the </results> to the end of file? Is better to use Nokogiri? Or is better to generate my XML manually? I'm trying to use that with Watir unit testing, there's something can I use to do that to write my results on a XML file?
(Update)That's the XML I want:
<?xml version="1.0" encoding="UTF-8"?>
<results result="result">
<test name="name1">
<hello>hello1</hello>
</test>
<test name="name2">
<hello>hello2</hello>
</test>
</results>
Thanks.
It's writing precisely what you're telling it to.
Pass a block into initXML (which would be init_xml in idiomatic Ruby, IMO) and execute it. But I wouldn't call it init_xml, because what you're actually doing is wrapping XML content.
I'm not sure what you're trying to accomplish; this is easily done using normal builder semantics. If you want to return XML nodes from a method consider passing the current node to a method, perhaps. Without knowing precisely what you're trying to do, it's difficult to advise.

Sparkle Framework problem (not displaying right version)

I am using sparkle framework for the first time. I am trying to test it out and everything works perfectly, except it doesn't display the update version correctly. So for example this is my xml file on server:
<?xml version="1.0" encoding="utf-8"?> <rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/"> <channel>
<title>Your Great App's Changelog</title>
<link>http://localhost/test/SampleAppcast.xml</link>
<description>Most recent changes with links to updates.</description>
<language>en</language>
<item>
<title>Version 1.5 (2 bugs fixed; 3 new features)</title>
<sparkle:releaseNotesLink>
http://localhost/test/notes.html
</sparkle:releaseNotesLink>
<pubDate>Wed, 15 Mar 2011 19:20:11 +0000</pubDate>
<enclosure url="http://localhost/test/seglab.zip" sparkle:version="2.0" length="1623481" type="application/octet-stream" sparkle:dsaSignature="MCwCFD8H0l7NOhl7OXeqVM1+CeonHuKtAhRQXdB4alDeMPgSUaHhuX1Zx5GwTg==" />
</item>
</channel> </rss>
notice in the title tag, the name of the version is 1.5, but when I get a prompt for sparkle update, it says "App Name version 2.0 is now available - you have 1.0...."
It should say 1.5...
Why is this happening?
Thanks!
"It should say 1.5" as in, "App Name version 1.5 is now available - you have 1.0...."?
Then you probably need to change this tag:
<enclosure
url="http://localhost/test/seglab.zip"
sparkle:version="2.0"
length="1623481"
... />
to this:
<enclosure
url="http://localhost/test/seglab.zip"
sparkle:version="1.5"
length="1623481"
... />
Full disclosure: I have never used Sparkle before. This is just a guess based on eyeballing the XML.

Resources