XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Inserting a text node before an element node useing the XML DOM

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]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS