473,466 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

xml parsing

Hi, NG!

I've spent many hours trying to understand why the dom-functions in
php do this and that, but the following I can't understand:

My xml-file looks like:

<Data>
<Article>
<Number>3746</Number>
<Description>This is the article description</Description>
<Groups>
<Group1>Group1</Group1>
<Group2>Group2</Group2>
<Group3>Group3</Group3>
</Groups>
</Article>
</Data>

having the current node "Groups", I call

//-- snip
$childNodes = $curNode->child_nodes();
echo "Number of child-nodes: " . count($childNodes) . "<br>";
//-- /snip

The output is: "Number of child-nodes: 7"

When I echo the node_name() of each child-node, every second node is
called #text

Could anyone of you explain why php reacts like this? I would expect a
child-count of three and definitely no #text-nodes...

Thanks in advance,

Gert.
Jul 17 '05 #1
3 1702
Gert Mellak wrote:
<Groups>
<Group1>Group1</Group1>
<Group2>Group2</Group2>
<Group3>Group3</Group3>
</Groups>
<snip>
$childNodes = $curNode->child_nodes();
echo "Number of child-nodes: " . count($childNodes) . "<br>";
//-- /snip

The output is: "Number of child-nodes: 7"

When I echo the node_name() of each child-node, every second node is
called #text

Could anyone of you explain why php reacts like this? I would expect a
child-count of three and definitely no #text-nodes...


The whitespace is counted as text nodes. If you had the whole thing on one
line without any whitespace, it should be as you were expecting. I don't
like DOM for many reasons, but that's another topic.
Jul 17 '05 #2
Gert Mellak wrote:
Hi, NG!

I've spent many hours trying to understand why the dom-functions in
php do this and that, but the following I can't understand:

My xml-file looks like:

<Data>
<Article>
<Number>3746</Number>
<Description>This is the article description</Description>
<Groups>
<Group1>Group1</Group1>
<Group2>Group2</Group2>
<Group3>Group3</Group3>
</Groups>
</Article>
</Data>

having the current node "Groups", I call

//-- snip
$childNodes = $curNode->child_nodes();
echo "Number of child-nodes: " . count($childNodes) . "<br>";
//-- /snip

The output is: "Number of child-nodes: 7"

When I echo the node_name() of each child-node, every second node is
called #text

Could anyone of you explain why php reacts like this? I would expect a
child-count of three and definitely no #text-nodes...


The whitespace (i.e. the newline char) between e.g. </Group1> and <Group2>
is considered text.

Berislav

--
If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
Groucho, Chico, and Harpo, then Usenet is Zeppo.
Jul 17 '05 #3
Gert Mellak wrote:
Could anyone of you explain why php reacts like this? I would expect a
child-count of three and definitely no #text-nodes...


In addition to Berislav's reply;

You can stop this behaviour by using the DOMXML_LOAD_DONT_KEEP_BLANKS
constant as the second argument of the domxml_open_file() call.
JW

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
0
by: Pentti | last post by:
Can anyone help to understand why re-parsing occurs on a remote database (using database links), even though we are using a prepared statement on the local database: Scenario: ======== We...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
5
by: randy | last post by:
Can some point me to a good example of parsing XML using C# 2.0? Thanks
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
7
by: Daniel Fetchinson | last post by:
Many times a more user friendly date format is convenient than the pure date and time. For example for a date that is yesterday I would like to see "yesterday" instead of the date itself. And for...
1
by: eyeore | last post by:
Hello everyone my String reverse code works but my professor wants me to use pop top push or Stack code and parsing code could you please teach me how to make this code work with pop top push or...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.