答案://start
header("Content-Type:text/xml;charset=utf-8");
$xmlstr = '<person> <child role="son"><child role="daughter"/></child><child ole="daughter"><child role="son"><child role="son"/></child></child></person>';
$sxe = new SimpleXMLElement($xmlstr);
echo $sxe->asXML();
//end
SimpleXMLElement {
SimpleXMLElement::addAttribute — Adds an attribute to the SimpleXML element
SimpleXMLElement::addChild — Adds a child element to the XML node
SimpleXMLElement::asXML — Return a well-formed XML string based on SimpleXML element
SimpleXMLElement::attributes — Identifies an element's attributes
SimpleXMLElement::children — Finds children of given node
SimpleXMLElement::__construct — Creates a new SimpleXMLElement object
SimpleXMLElement::getDocNamespaces — Returns namespaces declared in document
SimpleXMLElement::getName — Gets the name of the XML element
SimpleXMLElement::getNamespaces — Returns namespaces used in document
SimpleXMLElement::registerXPathNamespace — Creates a prefix/ns context for the next XPath query
SimpleXMLElement::xpath — Runs XPath query on XML data
/* Methods */
void addAttribute ( string $name , string $value [, string $namespace ] )
SimpleXMLElement addChild ( string $name [, string $value [, string $namespace ]] )
mixed asXML ([ string $filename ] )
SimpleXMLElement attributes ([ string $ns [, bool $is_prefix ]] )
SimpleXMLElement children ([ string $ns [, bool $is_prefix ]] )
array getDocNamespaces ([ bool $recursive ] )
string getName ( void )
array getNamespaces ([ bool $recursive ] )
bool registerXPathNamespace ( string $prefix , string $ns )
array xpath ( string $path )
}
其他:$xmlobj = simplexml_load_file($filename);
就可以把一个文件生成xml对象
上一个:有关一些PHP的SELECT问题
下一个:请教怎么弄一个php编写的日历?