tags:

views:

37

answers:

1

Greetings, I've read some threads about this topic, but actually I was unable to find or to think of a adequate solution (see for example: http://stackoverflow.com/questions/121656/regular-expression-to-remove-xml-tags-and-their-content).

I have an xml tag like that:

<bla_tag size="100"
         diameter="50"
         ratio="0.2"
         path="/user/home/something.pdf">
</bla_tag>

Aim: Having a regular expression that removes everything in between <bla_tag ...> .

Problem: the values like size, etc. change in each of the bla_tags (about 1000 bla-tags in the file).

Failed attempt: I tried it with: <bla_tag .*?> (the ? to make it less greedy...). Result of failure: Only <bla_tag has been marked, but not the content within the entire bracket!

What am I doing wrong - or is it actually possible to solve this problem based on regex (I read somewhere that it would not be possible due to xml property to be an type-2 language, can you confirm that?)

Thanks in advance and with best regards

Daniyal

+3  A: 

You want to read http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454

Seriously.

Use an xml parser. (They're not hard to use, honestly). They generally come in one of two flavours - SAX, and DOM, and you're probably going to prefer SAX.

My favorite parser is expat, but they all each have their little subtleties so it's not always a one-size-fits-all.

Arafangion