Jochem, thank you for your input!
So, right now I am able to access all text nodes by e.g.
$nodeElement -> parentNode -> childNodes -> item(0); -> returns
Lenght, Width and so on
$nodeElement -> parentNode -> childNodes -> item(1); -> is empty
$nodeElement -> parentNode -> childNodes -> item(2); -> returns mm,
kg ...
and so on. Or is there an easier way? When trying to acces the items by
($nodeElement containing text nodes)
$nodeElemtent -> item(0);
I get the following error message: Call to undefined method
DOMText::item()...
BTW, is there an easy way to get the total amount of items in a
curent node? count ( $nodeElement -> parentNode -> childNodes )
always returns 1. For now the only solution I know of is looping
through the nodeElements (e.g. foreach ( $nodeElement as $value ) and
have a counter inside the loop.
Thank you so far.
/frank
ps. I am desperately looking for some good sites covering the PHP DOM
functions. On www.php.net/dom there are barely some examples. And on
www.zend.com I only found one article with very, very basic examples.
Any ideas/suggestions are more than welcome. ds.
7 jun 2006 kl. 00.54 skrev Jochem Maas:
Frank Arensmeier wrote:
Hello!
Basically, I am working on a script that is supposed to convert table
data from metric to imperial data. I want to pare XHTML pages
(containing up to three different tables) with the PHP DOM
functions in
order to be able to access and manipulate the tables one by one.
Parsing
and retrieving table headers and cells is not the problem. The
problem
right now is how to replace data in the headers.
Here is a rather simplified example of a table I want to convert:
Header contains: Product | Lenght <br /> mm | Width <br />mm |
Weight
<br /> kg
As you can see, table headers can contain one or more words and a
(optional) line break. Currently, I am able to get all headers as
a list
of nodes from where I can access all headers one by one. But when
I try
to replace some content like this:
# $nodeElement contains the current text node from a header
not all of it - because the 'current' text is actual a series of
text and xml nodes (each <br /> and the text between being a
seperate node)
$str = "some new content";
$new_header_element = $doc -> createTextNode ( $str );
$nodeElement -> parentNode -> replaceChild ( $new_element,
$nodeElement );
you'll need to remove all children of parentNode and then append
the new node
(for arguments sake - you could do it another way but the result
would/should be
the same) because the contents of the 'Header' (the parentNode) is
actually a
set of nodes:
i.e. this:
Product | Lenght <br /> mm | Width <br />mm | Weight
ammounts to this (pseudo markup):
<textNode/><xmlNode/><textNode/><xmlNode/><textNode/>
and you are currently replacing only the first [text]node
hth
.. I am able to replace e.g. "Product", "Length" or "Width". I am not
able to access / replace anything after the line-break. Why? I have
already tested to get to this content with $nodeElement ->
childNodes;
but this will throw an error.
Hopefully, I was able to explain my problem to you... OOP and
especially
working with the DOM functions are still very new to me, so please be
patient with me.
If anyone has an idea, I would love to hear about it. Otherwise,
there
might be someone how can point me to some good on-line
documentation /
tutorials regarding PHP DOM functions.
Thank you and good night.
/frank
--PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php