[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Re: Inserting a text node before an element node useingthe

  • From: Jan-Arve Sæther <jasaethe@t...>
  • To: xml-dev@l...
  • Date: Tue, 10 Oct 2006 20:27:31 +0200

javascript has parentnodes
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@g...> 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@l...
> subscribe: xml-dev-subscribe@l...
> 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]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.