[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]
Re: [xml-dev] Re: Inserting a text node before an element node useingthe XML DOM
- From: Jan-Arve Sæther <jasaethe@trolltech.com>
- To: xml-dev@lists.xml.org
- Date: Tue, 10 Oct 2006 20:27:31 +0200
Hi, Spencer.
I am not sure what parentNodes does, but the cNode is really a sibling
of the <em> element.
You can try this:
var cNode = x.getElementsByTagName("em")[0].previousSibling;
cNode.insertData(0, strText);
hope this helps,
Jan- Arve
Spencer Tickner wrote:
> Sorry, typo.
>
> the line:
>
> // this just creates an error "cNode" has no properties
> cNode.insertData(0, String.fromCharCode(keycode));
>
> should be:
>
> // this just creates an error "cNode" has no properties
> cNode.insertData(0, strText);
>
> On 10/10/06, Spencer Tickner <spencertickner@gmail.com> wrote:
>
>> Hi List,
>>
>> I hope this question is appropriate for this list. I am retrieving an
>> xml document through AJAX and now would like to use the XML DOM to
>> insert some text before a <em> tag. I'm having a really difficult time
>> trying to pinpoint this location useing the XML DOM.
>>
>> XML
>>
>> <?xml version="1.0"?>
>> <data>
>> <para>This is a paragraph <em>Inline Date</em> that will have
>> to be
>> taken care of</para>
>> <para>Another paragraph with a list of fruit
>> <fruit>Apple</fruit>
>> <fruit>Orange</fruit>
>> </para>
>> </data>
>>
>> After I insert the text node I would like the xml to look like:
>>
>> <?xml version="1.0"?>
>> <data>
>> <para>This is a paragraph with some <em>Inline Date</em> that
>> will
>> have to be taken care of</para>
>> <para>Another paragraph with a list of fruit
>> <fruit>Apple</fruit>
>> <fruit>Orange</fruit>
>> </para>
>> </data>
>>
>>
>> Javascript function
>>
>> function insertText(strText)
>> {
>> // retrieving our xml document from the parent frame page
>> var x = parent.xmldoc
>>
>> // quick test to ensure thate we are getting back the correct
>> information
>> var i, n_elems, elems =
>> parent.xmldoc.getElementsByTagName("em");
>> n_elems = elems.length;
>> for (i=0; i < n_elems; i++)
>> alert(elems[i].nodeName); // We get an alert with
>> "em" so our XML Doc is valid
>>
>> // This is where things get sketchy, trying to reference the
>> text node before the <em>
>> var cNode = x.getElementsByTagName("em")[0].parentNodes[0];
>>
>> // this just creates an error "cNode" has no properties
>> cNode.insertData(0, String.fromCharCode(keycode));
>>
>> }
>>
>> So there it is, thanks in advance for the help. I should also mention
>> that in some instances the <em> tag will be right up against the
>> <para> tag but text should be inserted as before.
>>
>> Thanks,
>>
>> Spencer
>>
>
> _______________________________________________________________________
>
> XML-DEV is a publicly archived, unmoderated list hosted by OASIS
> to support XML implementation and development. To minimize
> spam in the archives, you must subscribe before posting.
>
> [Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
> Or unsubscribe: xml-dev-unsubscribe@lists.xml.org
> subscribe: xml-dev-subscribe@lists.xml.org
> List archive: http://lists.xml.org/archives/xml-dev/
> List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
>
--
Jan- Arve Sæther - jasaethe [at] trolltech [dot] com
Trolltech AS - Sandakerveien 116 - PO Box 4332 Nydalen - 0402 Oslo, Norway
[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]