[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Inserting a text node before an element node useing the XML DOM
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 >
[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! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|