[XML-SIG] Re: no parent?

Andrew Clover and-xml at doxdesk.com
Thu Oct 14 17:54:53 CEST 2004

Matthias Teege <matthias-gmane at mteege.de> schrieb:

> How do I get the content in the placeholder tag?

If you're sure the tag contains only simple text, you can access the 
value of the single Text node that will be inside it. eg.

   data= placeholder.firstChild.data
   replacement= translationLookup[data]
   text= document.createTextNode(replacement)

> I only get the attributes with 'placeholder.attributes.items()'.

Yep, you want the childNodes, not the attributes. The 'firstChild' 
property is shorthand for 'childNodes[0]'.

(BTW: avoid using Python dictionary methods like items() on NamedNodeMap 
objects like Element.attributes; it is not specified what this will do 
if anything, and different DOM implementations do slightly different 

> Later I'll try to replace placeholders in nested elements because I
> need to insert tables. Is this a lot more work?

Do you really mean nested placeholder elements, ie.:

     <text:placeholder> spam </text:placeholder>

If you just mean nested tables with simple placeholders inside them 
somewhere, that's no problem, getElementsByTagName will still happily 
root them out wherever they are in the document.

Andrew Clover
mailto:and at doxdesk.com

More information about the XML-SIG mailing list