Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > xmllint --xpath add new line to output

Reply
Thread Tools

xmllint --xpath add new line to output

 
 
sky
Guest
Posts: n/a
 
      12-12-2012
The output from running the following command is concatenated together, how do I add a new line to each result?

Here is the xml file:

<?xml version="1.0" encoding="UTF-8"?>
<digital_tpp cycle="1213" from_edate="0901Z 12/13/12" to_edate="0901Z 01/10/13">
<state_code ID="AK" state_fullname="Alaska">
<city_name ID="ADAK ISLAND" volume="AK-1">
<airport_name ID="ADAK" military="N" apt_ident="ADK" icao_ident="PADK" alnum="1244">
<record>
<chartseq>10100</chartseq>
<chart_code>MIN</chart_code>
<chart_name>TAKEOFF MINIMUMS</chart_name>
<useraction/>
<pdf_name>AKTO.PDF</pdf_name>
<cn_flg>N</cn_flg>
<cnsection/>
<cnpage/>
<bvsection>L</bvsection>
<bvpage/>
<procuid/>
<two_colored>N</two_colored>
<civil> </civil>
<faanfd15/>
<faanfd18/>
<copter/>
</record>
<record>
<chartseq>53525</chartseq>
<chart_code>IAP</chart_code>
<chart_name>RNAV (GPS) RWY 23</chart_name>
<useraction/>
<pdf_name>01244R23.PDF</pdf_name>
<cn_flg>N</cn_flg>
<cnsection/>
<cnpage/>
<bvsection> </bvsection>
<bvpage>1</bvpage>
<procuid>15177</procuid>
<two_colored>Y</two_colored>
<civil>C</civil>
<faanfd15>P23</faanfd15>
<faanfd18>R23</faanfd18>
<copter>N</copter>
</record>
<record>
<chartseq>57000</chartseq>
<chart_code>IAP</chart_code>
<chart_name>NDB/DME RWY 23</chart_name>
<useraction/>
<pdf_name>01244ND23.PDF</pdf_name>
<cn_flg>N</cn_flg>
<cnsection/>
<cnpage/>
<bvsection> </bvsection>
<bvpage>2</bvpage>
<procuid>15176</procuid>
<two_colored>Y</two_colored>
<civil>C</civil>
<faanfd15>N23</faanfd15>
<faanfd18>Q23</faanfd18>
<copter>N</copter>
</record>
</airport_name>
</city_name>
</state_code>
</digital_tpp>

Here is the command I'm running to select the value between the pdf_name tags

bash$ xmllint --xpath '//airport_name[@apt_ident="ADK"]/record[chart_code="IAP" or "DP" or "STAR" or "APD"]/pdf_name/text()' file.xml

Here is what the output looks like, as you can see it is missing new lines between the values returned, how do I add new lines?

AKTO.PDF01244R23.PDF01244ND23.PDFbash$

I want the output to look like this

AKTO.PDF
01244R23.PDF
01244ND23.PDF
 
Reply With Quote
 
 
 
 
Manuel Collado
Guest
Posts: n/a
 
      12-12-2012
El 12/12/2012 18:30, sky escribió:
> The output from running the following command is concatenated together, how do I add a new line to each result?
>
> Here is the xml file:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <digital_tpp cycle="1213" from_edate="0901Z 12/13/12" to_edate="0901Z 01/10/13">
> <state_code ID="AK" state_fullname="Alaska">
> <city_name ID="ADAK ISLAND" volume="AK-1">
> <airport_name ID="ADAK" military="N" apt_ident="ADK" icao_ident="PADK" alnum="1244">
> <record>
> <chartseq>10100</chartseq>
> <chart_code>MIN</chart_code>
> <chart_name>TAKEOFF MINIMUMS</chart_name>
> <useraction/>
> <pdf_name>AKTO.PDF</pdf_name>
> <cn_flg>N</cn_flg>
> <cnsection/>
> <cnpage/>
> <bvsection>L</bvsection>
> <bvpage/>
> <procuid/>
> <two_colored>N</two_colored>
> <civil> </civil>
> <faanfd15/>
> <faanfd18/>
> <copter/>
> </record>
> <record>
> <chartseq>53525</chartseq>
> <chart_code>IAP</chart_code>
> <chart_name>RNAV (GPS) RWY 23</chart_name>
> <useraction/>
> <pdf_name>01244R23.PDF</pdf_name>
> <cn_flg>N</cn_flg>
> <cnsection/>
> <cnpage/>
> <bvsection> </bvsection>
> <bvpage>1</bvpage>
> <procuid>15177</procuid>
> <two_colored>Y</two_colored>
> <civil>C</civil>
> <faanfd15>P23</faanfd15>
> <faanfd18>R23</faanfd18>
> <copter>N</copter>
> </record>
> <record>
> <chartseq>57000</chartseq>
> <chart_code>IAP</chart_code>
> <chart_name>NDB/DME RWY 23</chart_name>
> <useraction/>
> <pdf_name>01244ND23.PDF</pdf_name>
> <cn_flg>N</cn_flg>
> <cnsection/>
> <cnpage/>
> <bvsection> </bvsection>
> <bvpage>2</bvpage>
> <procuid>15176</procuid>
> <two_colored>Y</two_colored>
> <civil>C</civil>
> <faanfd15>N23</faanfd15>
> <faanfd18>Q23</faanfd18>
> <copter>N</copter>
> </record>
> </airport_name>
> </city_name>
> </state_code>
> </digital_tpp>
>
> Here is the command I'm running to select the value between the pdf_name tags
>
> bash$ xmllint --xpath '//airport_name[@apt_ident="ADK"]/record[chart_code="IAP" or "DP" or "STAR" or "APD"]/pdf_name/text()' file.xml
>
> Here is what the output looks like, as you can see it is missing new lines between the values returned, how do I add new lines?
>
> AKTO.PDF01244R23.PDF01244ND23.PDFbash$
>
> I want the output to look like this
>
> AKTO.PDF
> 01244R23.PDF
> 01244ND23.PDF
>


The output of xmllint is correct. The text nodes containing the newlines
are not selected by the given XPath expression.

To add newlines after each matched node you have to use a different
tool. You could write an XSLT transformation (instead of just a XPath
expression) and apply it with an XSLT processor.

Fortunately, there is xmlstarlet (the executable is "xml"), that you can
use instead of xmllint. xmlstarlet is a tool that automagically can
internally create the XSLT for you in some simple cases.

The particular command line in your case is (warning, single long line
probably wrapped in the message):

xml sel -t -m "//airport_name[@apt_ident='ADK']/record[chart_code='IAP'
or 'D P' or 'STAR' or 'APD']/pdf_name/text()" -c "." -n file.xml

It gives:

AKTO.PDF
01244R23.PDF
01244ND23.PDF

Caveat: it takes some time to master the intricacies of the command line
parameters of xmlstarlet.

--
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
idref, key and xmllint maxwell@ldc.upenn.edu XML 2 03-15-2007 01:59 PM
xmllint & dom.Writer Geoff XML 2 10-16-2006 02:05 AM
xmllint and xsd & how to check dtd/schema/etc Stan R. XML 4 06-08-2006 05:34 PM
line-by-line output from a subprocess Chermside, Michael Python 2 05-24-2005 01:02 AM
Using xmllint and xpath without --shell Neil McNaughton XML 1 01-08-2005 04:40 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57