Jump to content

Getting attribute of an xml file


hmdnawaz

Recommended Posts

:'(

I want to remove the current attribute of the tag and add the new one.

I wrote the php program but it gives me no output.

 

 

Can someone help me please???

 

 

 

Here is my code!!!

 

<?php

$xml = new DOMDocument();

$xml->load('test.xml');

 

$node = $xml->getElementsByTagName('*');

 

$nodename = "";

$node_name = "";

$att = "";

$attr_name = "";

$attr_value = "";

 

foreach($node as $value)

{

 

 

echo "Node Name is :".$value->nodeName;

 

 

 

$nodename = $value->nodeName;

$node_name = $xml->getElementsByTagName('$nodename')->item(0);

echo  $nodename;

 

foreach($nod_name as $value1)

{

$att = $node_name->getAttributeNode('$value1');

 

 

echo "Node Name is :".$att->name;

echo "<BR>Attribute Value is :".$att->value;

 

 

$attr_name = $att->name;

$attr_value = '"' . $att->value . '"';

$nodename->removeAttributeNode('$attr_name');

 

$nodename->setAttributeNode(new DOMAttr('$attr_name', '$attr_value'));

 

}

$xml->save('temp1.xml');

}

?>

Link to comment
https://forums.phpfreaks.com/topic/222563-getting-attribute-of-an-xml-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.