I have a small xml document from which I need to extract some values using xmllint. I am able to navigate through the xml hierarchy using xmllint --shell xmlfilename command.
But I am unable to extract the values. I don't want to use a grep / any pattern matching command, as that is already done and is a success.
I would appreciate any help regarding the xmlliint.
Here is my document in png format. I want to extract the 300$ and 500$ (the value).
<?xml version="1`.`0" encoding="ISO-8859-1"?>
<adi>
<asset>
<electronics item="Mobile" name="Nokia" value="300$" />
<electronics item="Mobile" name="Sony" value="500$" />
</asset>
</adi>
Another doubt is, are the two sets, the different representation of same xml ?
<?xml version="1.0 encoding="ISO-8859-1"?>
<adi>
<asset>
<electronics>
<item> Mobile </item>
<name>Nokia</name>
<value>300$</value>
</electronics>
<electronics>
<item> Mobile </item>
<name>Sony</name>
<value>500$</value>
</electronics>
</asset>
</adi>
With regards to your second question, those two snippets do not represent the same XML content. Attributes and child elements are not equivalent. A child element can be the root element of some arbitrary XML tree, but attributes are atomic.
E.g., I could modify the second snippet like this:
<?xml version="1.0 encoding="ISO-8859-1"?>
<adi>
<asset>
<electronics>
<item>
Mobile
<sub-item>Phone</sub-item>
</item>
<name>Nokia</name>
<value>300$</value>
</electronics>
<electronics>
<item> Mobile </item>
<name>Sony</name>
<value>500$</value>
</electronics>
</asset>
</adi>
where I have added <sub-item>Phone</sub-item> to the first <item> element.
However, there's no equivalent if item is an attribute instead, as in the first snippet.
Late but while searches for the tag xmllint match the first page, I answer you now ;)
use --xpath instead of --xpath like below
xmllint --xpath '//electronics/value/text()' second-xml_file.xml
Related
Hi I need to convert the following input xml to the below mentioned output xml using xsl 2.0 version. I'm pretty new to xslt and I've tried using apply-templates and for-each-group to get a distinct collection of clients.
Input:
<?xml version="1.0" encoding="utf-8" ?>
<ITEM>
<allCounselling>
<ITEM>
<allAttendingPeople>
<ITEM>
<PersonKey>1</PersonKey>
</ITEM>
</allAttendingPeople>
<allSessions>
<ITEM>
<KEY></KEY>
<DATE>12 Dec 2014</DATE>
<allAttendedPeople>
<ITEM>
<PersonKey>1</PersonKey>
</ITEM>
<ITEM>
<PersonKey>2</PersonKey>
</ITEM>
</allAttendedPeople>
</ITEM>
</allSessions>
</ITEM>
</allCounselling>
</ITEM>
Required Output is
<Clients>
<Client>
<ClientId>1</ClientId>
</Client>
<Client>
<ClientId>2</ClientId>
</Client>
</Clients>
The PersonKey value is the ClientId and should be a distinct collection.
The other difficult part is that I have to filter the sessions also. If the session Item is within a given date range, then I should only out put the persons within that allAttendedPeople collection of those filtered sessions and then I have to traverse up to get the counselling item which contains those sessions and out put all attending people...I know it's pretty hectic :'(
Please help!
I have the xml structure xml like that:
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">
<channel>
<item>
<comments>http://www.rtl.fr/actu/politique/laurent-gerra-imitant-nicolas-sarkozy-il-faut-barrer-la-
<slash:comments>0</slash:comments>
</item>
</channel>
</rss>
How can I get text in <slash:comments> tag.
I already try(Swift version):
elementItem.child("comments",inNamespace: "slash").
But it don't work.
As stated here, RaptureXML deletes namespaces, so you can access your content via
elementItem.child("comments")
I'm studying Apple's LazyTableImages sample code. I'd like to understand how the app is pulling data from the RSS feed included in the app:
http://phobos.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/toppaidapplications/limit=75/xml
How are the contents at the above url parsed? Viewing the page source reveals HTML with no apparent xml section. While looking through the sample parsing code I found a few symbols like im:name. However these symbols are not in the contents of the above url.
I tried to host the contents of the above url locally (w/ limit=1). However pointing the sample code to #"~/Desktop/a.xml" causes the application to throw the error unsupported url.
More info: While reading http://en.wikipedia.org/wiki/Rss I came across what I expected to see at phobos link above. Something like this:
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>RSS Title</title>
<description>This is an example of an RSS feed</description>
<link>http://www.someexamplerssdomain.com/main.html</link>
<pubDate>Mon, 06 Sep 2009 16:45:00 +0000 </pubDate>
<item>
<title>Example entry</title>
<description>an interesting description</description>
<link>http://www.wikipedia.org/</link>
<guid>unique string per item</guid>
<pubDate>Mon, 06 Sep 2009 16:45:00 +0000 </pubDate>
</item>
</channel>
</rss>
Is there an equivalent "human-readable" xml document corresponding to the above phobos link somewhere?
You're right, the feed you're looking at technically isn't an RSS Feed. It's an Atom 1.0 Feed, but both are popular XML-based feed formats.
If you view the source of the feed you will see the XML elements you're looking for, like:
<entry>
<updated>2011-12-09T16:15:32-07:00</updated>
<id>http://itunes.apple.com/us/app/tetris/id479943969?mt=8&uo=2</id>
<title>TETRISĀ® - Electronic Arts</title>
<summary>Long summary here</summary>
<im:name>TETRISĀ®</im:name>
...
</entry>
Some browser versions parse RSS/Atom feeds into user-friendly HTML pages and present them instead of the actual feed, it sounds like that's the type of HTML page you're viewing.
On a OS X, you could use a command like Curl to download the feed in a Terminal:
curl -o feed.xml http://phobos.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/toppaidapplications/limit=75/xml
I am trying to build a Standalone VoiceXML parser which accepts the input as the example below
<grammar version="1.0" root="ROOT" mode="dtmf">
<rule id="ROOT">
<one-of>
<item> 1 </item>
<item> 2 </item>
<item> 3 </item>
<item> 4 </item>
<item> 5 </item>
</one-of>
</rule>
</grammar>
It is easy to write a specific parser for that specific grammar specification. However, I want to have a generic solution/algorithm which can parse/interpret all possible DTMF grammar cases.
I appreciate any help.
Thanks,
-Toan.
There is a very good open source which implements a VXML interpreter. It is JVoiceXML at http://jvoicexml.sourceforge.net/
It also includes a VXML grammar validation engine. I think this is what I am looking for.
Take a look at NuGram.
Open VXI is another open source solution that has been around for a long time. A lot of major telephony vendors have used this as the basis for their IVR platforms.
I'm using rails and the Nokogiri parser. My xml is as below and I'm trying to get the 'Biology: 08:00' text into my view.
<rss version="2.0">
<channel>
<item>
<title>Biology: 08:00</title>
<description>Start time of Biology</description>
<pubDate>Tue, 13 Oct 2009 UT</pubDate>
</item>
</channel>
</rss>
I can find the node with the text 'biology' using the code below
#content = doc.xpath('//title[contains(text(),"Biology")]')
When I move it into my view it strangely ends up as the title of my .html.erb page. I can't seem to get it into the body with
<body>
<%=#content%>
</body>
anyone know what's going on?
You're getting the whole node, and the node is a <title> tag.
you want:
#content = doc.xpath('//title[contains(text(),"Biology")]/text()')
to get the text content of the node