Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
xml help
Shakti_ThePower
I need to delete the <metatags> tag from xml file. How can I do using perl.
<?xml version="1.0" encoding="UTF-8"?>
<content name="airquality">
<metatags>
<meta content="dfds" name="dsffd"/>
</metatags>
<htmlpara>xyz
</htmlpara>
</content>
Richa Dalwala
Interwoven Consultant
Find more posts tagged with
Comments
Migrateduser
Here's a stab...
$xml =~ s/(.*)<metatags>[.*]</metatags>(.*)/$1$2/g;
You might need to play with the regex a bit, but I'm hoping this is a good start.
dave@simpleinternet.com
+USA (215) 962-5153
Adam Stoller
If you're going to play around with XML files in Perl - take a look at one of the many Perl modules specifically for that purpose (XML:
arser, XML:
OM, TeamSite::XMLnode, etc.)
Using a regex could work - but you'll have to bullet-proof it against all sorts of different possible arangements such that you'd usually be better off if you just parsed the file as XML to begin with and didn't bother with the regex (IMO).
The regex posted (at this time) won't work because it's assuming a single-line upon which to act upon - which may or may not be the case - and isn't from the code you posted).
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
gzevin
yep, you are right.
however, if a regex is needed, the following simple regex will work:
$xml =~ s!</{0,1}metatags>!!gs;
Greg Zevin, Ph.D. Comp. Sc.
Independent Interwoven Consultant/Architect
Sydney, AU
New folder.zip
Migrateduser
> however, if a regex is needed, the following simple regex will work:
>
> $xml =~ s!</{0,1}metatags>!!gs;
This example demonstrates the point the Ghoti made. It will remove the 'metatags' start and end tags, but it will leave the 'meta' child elements behind. That probably isn't the desired result. It is usually more reliable to use those modules that were designed to handle XML.
Brinko Kobrin
Interwoven Staff Engineer
JonathonG
Just to add my $.02...
XML::Twig is a very nice library for manipulating XML. It provides methods to add or remove entire "chunks" of the XML tree. I used it extensively on a TeamXML project where we needed to manipulate XML files programmatically.
Jonathon
Independent Interwoven Contractor
gzevin
Brinko,
I was not arguing - it was just a point to make
(actually, one more regex would have gotten off <meta tags as well)
but I agree - using XML-specific modules to do some XML surgery is a better way
Greg Zevin, Ph.D. Comp. Sc.
Independent Interwoven Consultant/Architect
Sydney, AU
megamala
How can I get the values between [ and ] into an array using regex from the following string.
$str = qq(xyadfsd [x123] ddd dfdsf [read3] 33sdfa [val4] dfdskfjdksjf);
TIA
MM Guptha
Migrateduser
funny... I just wrote one of these just ten minutes ago. Try this...
$str = qq(xyadfsd [x123] ddd dfdsf [read3] 33sdfa [val4] dfdskfjdksjf);
my $match;
$match =~ m/[.*](\[[a-zA-Z0-9]+\])[.*](\[[a-zA-Z0-9]+\])[.*](\[[a-zA-Z0-9]+\])[.*])/;
push
@array
, ($1, $2, $3);
Dave
dave@simpleinternet.com
+USA (215) 962-5153
Jeremy
If you're happy to put it into an array then this would be a pretty good one:
@array
= ( $str =~ m|\[(.*?)\]|g );
Hope that works.
New_test.zip
megamala
Thanks, Thats what I am looking.
TIA
MM Guptha
output.pdf
Pagein.docx