Yes this is a very basic question :)

Text nodes are generated for all non-tag data. Your textnodes actually
contains data. They contain one newline character each.
If you do not want any textnodes then you have to strip your document from
ALL newlines, spaces and such that are not part of an element. This will
make the document almost unreadable for a human eye though.
Another way is to create a TreeWalker/TreeIterator that filters out all
textnodes during traveral of the DOMDocument or diong it manually by
checking the nodeType() for each node you process.

Regards

Erik Rydgren
Mandarinen systems AB
Sweden

-----Original Message-----
From: Axelle Apvrille (LMC) [mailto:[EMAIL PROTECTED]
Sent: den 28 februari 2003 17:57
To: [EMAIL PROTECTED]
Subject: Special #text nodes when parsing XML doc with DOM ?


Hi all,
I've basically written a small method that parses all elements of my XML
document. For each element, it prints out its name, value and type. I
retrieve the root node, then I retrieve its childs. Recursively I parse
childs of childs etc.

I've made it parse this very simple doc:
<?xml version='1.0' encoding='ascii'?>
<dsi:Information xmlns='http://www.w3.org/2001/XMLSchema'
 xmlns:dsi='http://www'>
<dsi:Alarm>toto</dsi:Alarm>
</dsi:Information>

I'm surprised it returns two nodes with name #text and no value... I'm
sure this is a pretty basic question, but what do those nodes represent
? what are they for ?

This is the output of my program:
Retrieving all nodes of the document
Root
  Name = dsi:Information
  Value= (null)
  Type = 1

- Name   = #text  <<<<<<<<<<<<<<<<<< what's this node for ?
- Value  =
                  <<<<<<<<<<<<<<<<<< no value ?
- Type   = 3
- Prefix = (null)

- Name   = dsi:Alarm
- Value  = (null)
- Type   = 1
- Prefix = dsi

-- Name   = #text
-- Value  = toto
-- Type   = 3
-- Prefix = (null)

-- Name   = #text  <<<<<<<<<<<<<<<<<< what's this node for ?
-- Value  =
                   <<<<<<<<<<<<<<<<<< no value ?
-- Type   = 3
-- Prefix = (null)

Thanks very much
Axelle.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to