Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: XML::Simple XML / XMLin / XMLout? or something else?

by Roboz (Novice)
on Oct 12, 2012 at 14:26 UTC ( [id://998697]=note: print w/replies, xml ) Need Help??


in reply to Re: XML::Simple XML / XMLin / XMLout? or something else?
in thread XML::Simple XML / XMLin / XMLout? or something else?

This also looks like it'll do what I need. Man all you folk are awesome! Thanks for the help.

Replies are listed 'Best First'.
Re^3: XML::Simple XML / XMLin / XMLout? or something else?
by McA (Priest) on Oct 12, 2012 at 14:42 UTC

    I can't resist: How does the output of the last approach differ from mine where I said you have to just throw away the <booklist> tag from your input file? By the way: Extra newlines are also simple.

    But if you really need perl:

    perl -ne 'print unless /booklist/' < data.xml

    Best regards
    McA

      How about if the xml gets received like this?

      <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

        :-))

        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

      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 :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://998697]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-03-19 04:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found