[Xml-coreutils-discuss] Where to start?
Status: Alpha
Brought to you by:
lbreyer
From: Douglas H. <do...@do...> - 2015-02-11 19:00:15
|
I need some help getting my thinking in the xml-coreutils world. I have some prepared data in the format: <response> <listing> <foo>foo</foo> <bar>bar</bar> <floor_plan>http://example.com/123456</floor_plan> <listing_id>1</listing_id> </listing> <listing> <listing_id>2</listing_id> <foo>foo</foo> <bar>bar</bar> </listing> </response> Each /response/listing element has a //listing_id and some, but not all listings have a floor_plan element. Goal: I would like to extract only listings with floor plans, and only the selected elements I am interested in, into a new document as: <listings> <listing> <listing_id>1</listing_id> <floor_plan>http://example.com/123456</floor_plan> </listing> <listings> I have tried commands such as: # Create the target file xml-echo -e "[listings@updated=20150210]" >listings.xml # Copy selected elements into target xml-cp page1.xml :/response/listing/listing_id[/response/listing/floor_plan != null] listings.xml :/listings/ I have read all the man pages and experimented with many different of the xml-* commands. Very seldom do they work as I am hoping. The workflow I would expect, based on the coreutils workflows I normally use, would be: cat source.xml | while read element; do if echo $element | grep -q floor_plan ; then echo $element >> target.xml fi done It would be nice if I could use a complement of the above technologies for processing the XML. The below are imaginary pseudo-commands: xml-cat source.xml :/response/listing | while xml-read listing; do # $listing is now an xml fragment of one listing element's full content if echo $listing | xml-grep -q ://floor_plan; then cat $element | xml-egrep "://listing|://listing/listing_id|://listing/floor_plan" | xml-insert target.xml :/listings/ fi done Perhaps by following my pseudo-logic, you can explain how I can carry out these operations with xml-coreutils. I have attached one of my source files. Regards, Doug -- Douglas Held do...@do... +447775733093 |