php怎么给xml节点添加属性值?
$xml=<<<EOT<?xmlversion="1.0"?><root><sectionname="Section1"><categoryid="Category1"n...
$xml =<<<EOT
<?xml version="1.0"?>
<root>
<section name="Section1">
<category id="Category1" name="google">
</section>
</root>
EOT;
比如怎么给section中添加一个属性,city='abc',使得$xml的结果是
<root>
<section name="Section1" city="abc">
<category id="Category1" name="google">
</section>
</root> 展开
<?xml version="1.0"?>
<root>
<section name="Section1">
<category id="Category1" name="google">
</section>
</root>
EOT;
比如怎么给section中添加一个属性,city='abc',使得$xml的结果是
<root>
<section name="Section1" city="abc">
<category id="Category1" name="google">
</section>
</root> 展开
展开全部
$xml =<<<EOT
<?xml version="1.0"?>
<root>
<section name="Section1">
<category id="Category1" name="google">
</section>
</root>
EOT;
$objXML=simplexml_load_string($xml);
$objXML->section->addAttribute('city', 'abc');
echo $objXML->asXML();
<?xml version="1.0"?>
<root>
<section name="Section1">
<category id="Category1" name="google">
</section>
</root>
EOT;
$objXML=simplexml_load_string($xml);
$objXML->section->addAttribute('city', 'abc');
echo $objXML->asXML();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询