And, arguably more important:
Note: This extension has been moved to the » PECL repository and is no longer bundled with PHP as of PHP 5.0.0.
Note: This extension is no longer marked experimental. It will, however, never be released with PHP 5, and will only be distributed with PHP 4. If you need DOM XML support with PHP 5 you can use the DOM extension. This domxml extension is not compatible with the DOM extension.
http://www.php.net/domxml
domxml_xmltree
(PHP 4 >= 4.2.0)
domxml_xmltree — Crée un arbre d'objets PHP à partir d'un document XML
Description
Cette fonction analyse le document XML passé dans la chaîne str et retourne un arbre d'objets PHP, représentant le document.
Cette fonction est isolée des autres, ce qui signifie que vous ne pouvez pas accéder aux objets de l'arbre avec les autres fonctions. Modifier l'arbre, par exemple en ajoutant des noeuds, n'a pas de sens car il n'y a pas moyen de convertir cet arbre fichier XML.
Cependant, cette fonction est pratique si vous vouez lire un fichier XML et en étudier le contenu.
Liste de paramètres
- str
-
Le contenu du fichier XML.
Valeurs de retour
Retourne un arbre d'objets Dom commençant par un DomDocument.
domxml_xmltree
MediaHound
20-Dec-2007 05:49
20-Dec-2007 05:49
jeroen dot s at zonnet dot nl
16-May-2006 10:36
16-May-2006 10:36
You can modify the returned DomDocument, and dump it as an XML file
by using DomDocument->dump_mem() or DomDocument->dump_file().
23-Feb-2005 03:38
Replacing line 10 works well, but replacing line 15 causes some errors. I have a tree like:
<admin>
<user level="0">
<username>admin</username>
<password>admin_pass</password>
</user>
<user level="1">
<username>moder</username>
<password>moder_pass</password>
</user>
</admin>
when I remove those brackets only the last <user> is included into array. In this example it would be
<user level="1">
<username>moder</username>
<password>juozux</password>
</user>
no user name admin, etc.
p.s. I don't store passwords in plain text in xml, that was just an example :))
Alan71
07-Feb-2004 07:05
07-Feb-2004 07:05
In the function of nutbar, try to replace line 10 by
$objptr = $branch->node_value();
and line 15 by :
$objptr = &$object[$branch->node_name()]; //without the '[]'
it makes an array much more easier to read.
Previously, it produces an array like $MyArray[ROOT][0][BRANCH1][0][BRANCH2][0][5], and now $MyArray[ROOT][BRANCH1][BRANCH2][5]. There isn't bugs in the example I use, and I haven't tested with arguments. I think that an implementation of a part of nospam's code is enough.
I hope this will help!
samc a t rampantlabs dot net
27-Dec-2002 09:36
27-Dec-2002 09:36
Forgive me if I am mistaken, but the whole point of including the "useless white space" is because of the existence of mixed types, for example:
the schema def:
<xsd:element name="paragraph">
<xsd:complexType mixed="true">
<xsd:choice>
<xsd:element ref="link" />
<xsd:element ref="emphasisText" />
</xsd:choice>
</xsd:complexType>
</xsd:element>
and an example:
<paragraph>This here is a paragraph. You'll notice that it has within it a bunch of text punctuated by other <emphasisText>tags</emphasisText> and it is <link target="me.html>my</url> understanding that the only way to read this text is by reading the tagless nodes that your functions strip.</paragraph>
I could be way off though...
colin at omenmedia dot com
13-Dec-2002 04:03
13-Dec-2002 04:03
This is a genuinely useful function, however, as with any DOM-based markup parser, be mindful of the size of the XML document you are parsing. Representing very large XML files as object structures requires *a lot* of memory and processing, and may even crash your server (which is what happened to my Apache when I tried parsing a 2MB XML file using this function, just for fun... ;).
nospam at candlefire dot org
15-Oct-2002 05:03
15-Oct-2002 05:03
Consider the following revisions for including attributes into the array.
function domxml_xmlarray ($branch)
{
$object = Array ();
$objptr =& $object;
$branch = $branch->first_child ();
while ($branch)
{
if (!($branch->is_blank_node()))
{
switch ($branch->node_type())
{
case XML_TEXT_NODE:
{
$objptr['cdata'] = $branch->node_value ();
break;
}
case XML_ELEMENT_NODE:
{
$objptr =& $object[$branch->node_name ()][];
if ($branch->has_attributes ())
{
$attributes = $branch->attributes ();
if (!is_array ($attributes)) { break; }
foreach ($attributes as $index => $domobj)
{
$objptr[$index] = $objptr[$domobj->name] = $domobj->value;
}
}
break;
}
}
if ($branch->has_child_nodes ()) { $objptr = array_merge ($objptr, domxml_xmlarray ($branch)); }
}
$branch = $branch->next_sibling ();
}
return $object;
}
nutbar at innocent dot com
13-Oct-2002 09:18
13-Oct-2002 09:18
Same concept as previous function, except uses node names as key items in the arrays. This function may prove a bit more useful than the previous one:
function domxml_xmlarray($branch) {
$object = array();
$objptr = &$object;
$branch = $branch->first_child();
while ($branch) {
if (!($branch->is_blank_node())) {
switch ($branch->node_type()) {
case XML_TEXT_NODE: {
$objptr['cdata'] = $branch->node_value();
break;
}
case XML_ELEMENT_NODE: {
$objptr = &$object[$branch->node_name()][];
break;
}
}
if ($branch->has_child_nodes()) {
$objptr = array_merge($objptr, domxml_xmlarray($branch));
}
}
$branch = $branch->next_sibling();
}
return $object;
}
Usage is identical to the previous function.
