php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42039 item function read xml
Submitted: 2007-07-19 03:04 UTC Modified: 2007-07-19 07:18 UTC
From: ichigoxi at gmail dot com Assigned:
Status: Not a bug Package: *XML functions
PHP Version: 5.2.3 OS: ubuntu/linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
35 + 1 = ?
Subscribe to this entry?

 
 [2007-07-19 03:04 UTC] ichigoxi at gmail dot com
Description:
------------
like this xml------->
<root>
<item>
<a>11</a>
<b>1</b>
<c>0</c>
</item>
</root>

$dom = new DOMDocument();
$dom->load('test.xml');
$root = $dom->documentElement;
$items = $root->childNodes;
$item = $items->item(0);
$itemChildren = $item->childNodes;
$b = $itemChildren->item(1);
echo $b->nodeValue;

this code can not read $b from the xml
but this xml---------->
<root><item><a>11</a><b>1</b><c>0</c></item></root>

the code can read $b 




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-19 06:06 UTC] chregu@php.net
Please read how DOM works. There are Textnodes between your Elements, 
which also count as items, so ->item(1) would be the a element in your 
example and item(3) the b element.

I'd advise you to use xpath for much more accurate pinpointing of 
nodes...
 [2007-07-19 07:18 UTC] ichigoxi at gmail dot com
thank you for your email,help me so much
but i also have question
that how to read the xml

<root><item><a>11</a><b>1</b><c>0</c></item></root>
------->
this xml
i can do the pro

$dom = new DOMDocument();
$dom->load('test.xml');
$root = $dom->documentElement;
$items = $root->childNodes;
$item = $items->item(0);
$itemChildren = $item->childNodes;
$b = $itemChildren->item(1);
echo $b->nodeValue;

but like this xml------->
<root>
<item>
<a>11</a>
<b>1</b>
<c>0</c>
</item>
</root>

if i read $b = $itemChildren->item(1) or item(3)
the php report that:
call to a member function item() on a non-object in .....

please help me how to write the function to read the xml,thank you very much
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu May 26 09:05:44 2022 UTC