Organizational Research By

Surprising Reserch Topic

regexp to add attribute in any xml tags


regexp to add attribute in any xml tags  using -'php,xml,regex'

I have well-formed xml documents into string variables. I want to use preg_replace to add a defined attribute to every xml tags.

For example replace:

<tag1>
<tag2> some text </tag2>
</tag1>


by:

<tag1 attr="myAttr">
<tag2 attr="myAttr"> some text </tag2>
</tag1>


So I basically need the regex expression to find any start tags and add my attribute, but I'm a complete regex noob.
    

asked Oct 11, 2015 by virendra.bajaj
0 votes
4 views



Related Hot Questions

2 Answers

0 votes
NULL
answered Oct 11, 2015 by sujata naik
0 votes
NULL
answered Oct 11, 2015 by sameer rathore

...