<booklist> <book> <author>Book 1 author 1</author> <author>Book 1 auth
+or 2</author> <title>Book 1 title</title> <isbn>Book1ISBN</isbn> </bo
+ok> <book> <author>Book 2 author 1</author> <author>Book 2 author 2</
+author> <title>Book 2 title</title> <isbn>Book2ISBN</isbn> </book> <b
+ook> <author>Book 3 author 1</author> <author>Book 3 author 2</author
+> <author>Book 3 author 3</author> <title>Book 3 title</title> <isbn>
+Book3ISBN</isbn> </book> </booklist>
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP Neil Armstrong
| [reply] [Watch: Dir/Any] [d/l] |
:-))
Yes, of course! That's why I wrote that I can't resist.
It was just how the initial question was formulated: I couldn't see if xml has to be parsed to work on the parsed data. Then his own approach would have been sufficient. The only problem I could see was the loss of element order. The other thing what I could see is a kind of extraction. But be aware: The resulting xml-snippets concatenated together don't form valid XML. XML mandates that you have to have one starting and ending tag containing all other tags. So the wished output is not valid XML. So, what is it good for? (He gave the answer meanwhile. This little add on let all others know the intention.)
So, if you don't need real XML parsing and you know the structure and layout of incoming XML you can do many things without parsing. To your example of having NO newlines:
xmllint --format data1.xml | perl -ne 'print unless /booklist|\?xml /'
Not perl related, but probably useful for Roboz while debugging his SOAP stuff: xmllint is an excellent command line tool (commonly in package libxml2). I hope that this last hint will be valueable at least :-))
Best regards
McA
| [reply] [Watch: Dir/Any] [d/l] [select] |
Hey McA,
One possibility (that I've run into myself) is $corporate mandates that say that data can't be edited by hand, and that you have to write a program (to be executed only by those with sufficient authority) to modify said data.
Of course, another possibility is that this is more than a one-time thing -- maybe these book list files show up daily.
A warning about your one-liner (cool though it is), XML documents don't necessarily have to have newlines between elements. I've encountered some with no newlines at all -- I believe your solution would empty the file in that case.
Just some random thoughts...
Update: And BrowserUk phrases it better than I :)
| [reply] [Watch: Dir/Any] [d/l] |