需要匹配HTML标记并在php中的xml文件周围插入另一个标记

I have a xml file (pretty large file) that has different html tags, for example

<?xml version="1.0" encoding="UTF-8"?>

-<feed xmlns="http://www.ixtens.com/xml/mbapi/R1.4">

Sloan Street Classic Tote in Red

<Attribute name="SupplierName" domain="CommonTaxonomy">Red</Attribute>

I want to add tags where there is an attribute. like below:

<Attribute name="SupplierName" domain="CommonTaxonomy"><value>Red</value></Attribute>

I tried everything in php, but can't get it right.

Please help me. i was looking as convert every character in string then preg match

But did not helped.

I have to do this for every tags with attributes. moreover to be changed to

How i did: (preg_match("/(?![^>]\bencoding)(?![^>]\bfeed)<[^>]+['=']/", $line, $matches)) preg_replace("/<(.+?[>^])>/","<$1><value>",$line)

But it is not working

regards, Maverick

Regex:

<(Attribute)(\b[^>]*>)([^<>]*)(?=<\/\1)

Replacement string:

<\1\2<value>\3</value>

DEMO

You can use this regex.

(<Attribute.*?>)(.*?)(<\/Attribute>)

Working demo

enter image description here

To deal with xml content you can use DOMDocument (that is designed for this kind of task):

$dom = new DOMDocument();
$dom->loadXML($data);

$AttributeTags = $dom->getElementsByTagName('Attribute');

foreach ($AttributeTags as $node) {
    $value = $node->nodeValue;
    $valueTag = $dom->createElement('value', $value);
    $node->replaceChild($valueTag, $node->firstChild);
}

echo htmlspecialchars($dom->saveXML());