Now that I've thought of a potential practical use for XML, I'm actually trying to implement it.

I've read through (skimmed, really) the PHP & XML articles on devshed, in the XML section... and I've been playing around with using the XML DOM, but have a few questions.

My XML document looks something like this:

<?xml version="1.0"?>
    <PAGE1>This is the first page of section 1.</PAGE1>
    <PAGE2>This is the second page of section 1.</PAGE2>
    <PAGE3>This is the third page of section 1.</PAGE3>
    <PAGE1>This is the first page of section 2.</PAGE1>
Now, I'm using the DOM to extract the root, and then list all of the children of the root. However, what's happening is that even though I have 2 children of the 'SITE' node, my code is reporting that there are more. I've checked the type for these other nodes, and they say they're text objects, but I can't figure out what they are.

Here's my code:
PHP Code:
  $xmlFile "C:\\My Documents\\XML\\xmldoc.xml";

$xmlDoc xmldocfile($xmlFile);

$docRoot $xmlDoc->root();

"The document root tag is: <i>" $docRoot->name "</i><br><br>\n");

$docChildren $docRoot->children();

"There are <b>" sizeof($docChildren) . "</b> children to the Document Root Tag.<br>\n");


$docChildren as $currChild)
    if (
$currChild->type == 1)
"<LI> Type: " $currChild->type " | " $currChild->name);
    else if (
$currChild->type == 3)
"<LI> Type: " $currChild->type " | " $currChild);

The output looks like:

Warning: Unexpected character in input: ' ' (ASCII=11) state=1 in c:\my documents\xml\testxml.php on line 45
The Document Root Tag is: SITE

There are 5 children to the Document Root Tag.

  • Type: 3 | Object
  • Type: 1 | SECTION1
  • Type: 3 | Object
  • Type: 1 | SECTION2
  • Type: 3 | Object

So my first question is, why am I getting that 'Unexpected character in input' error?
Secondly, what are those three other 'objects'? What are they used for?

Can anyone help me out?


- coredumped.