Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Strip out value between xml tags

by sauoq (Abbot)
on Mar 18, 2015 at 18:42 UTC ( [id://1120483]=note: print w/replies, xml ) Need Help??


in reply to Strip out value between xml tags

I'm trying to strip out the value that is between <CorpActnEvtId>12345678</CorpActnEvtId>.

By which, I think you mean you want to retrieve the value between the CorpActnEvtid opening and closing tags... (Strip out, to me, usually menas you want to delete it, and leave the rest.)

Parsing it with one of the XML modules is the right answer.

A quick answer, if this is a one-off thing or something, is to use something like

$junk =~ /<CorpActnEvtId>(\d+)<\/CorpActnEvtId>/; my $id = $1;

I might do it that way if I had a pile of data I had to munge up just once, and if I didn't need much more from that snippet of XML. But even so, it's making some assumptions (like the ID is always just digits and there is no whitespace within the tag.) This is terribly brittle and, if you have to do it once, you'll probably have to do it again. So I'm not recommending you do it this way, particularly as you weren't able to work it out on your own.

That said, here's some rope; it's up to you not to hang yourself with it.

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re^2: Strip out value between xml tags
by dirtdog (Monk) on Mar 24, 2015 at 14:33 UTC

    Thanks! I ended up using the following sed command:

    grep CorpActnEvtId | sed -e 's/.*<CorpActnEvtId>//' | sed -e 's/<\/Cor +pActnEvtId.*//' > file.out

    I apologize for the late response. Something urgently came up that day and i'm just now able to reply.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-24 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found