f



delete/remove node from XML with JavaScript

I am trying to delete all 'PiccoOption' nodes that i do not need, i
then want to put the document, with just one 'PiccoOption' into the
form field 'document.form.optionNumber.value'.
This code doesnt seem to work.....
Any help appreciated.
[code]
function loadXML()
{
	var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
	xmlDoc.async="false";
	xmlDoc.loadXML(document.form.optionXML.value); // The XML file (e.g.
'<PiccoReply><PiccoOption>....etc......')

	var optNo = parseFloat(document.form.optionNumber.value); // An
integer

	if (xmlDoc.documentElement.hasChildNodes)
	{
		var iNoOfOpts =
parseFloat(xmlDoc.documentElement.selectNodes("PiccoOption").length);

		for (i=0; i<iNoOfOpts; i++)
		{
			if (i!=optNo)
			{
				alert("Ref = " +
xmlDoc.documentElement.selectNodes("PiccoOption").item(i).selectNodes("Details").item(0).selectNodes("Ref").item(0).text);
				alert("i = " + i);
				alert("optNo = " + optNo);

				var delNode = xmlDoc.documentElement.childNodes
				delNode.removeChild(true);
			}
		}
	}
}
[/code]


My XML document:
[code]
<PiccoReply>
	<PiccoOption>
		<Details>
			<JourneyType>RETURN</JourneyType>
			<Ref>59</Ref>
		</Details>
	</PiccoOption>
	<PiccoOption>
		<Details>
			<JourneyType>GLASGOW</JourneyType>
			<Ref>9</Ref>
		</Details>
	</PiccoOption>
	<PiccoOption>
		<Details>
			<JourneyType>IRVINE</JourneyType>
			<Ref>9</Ref>
		</Details>
	</PiccoOption>
</PiccoReply>	
[/code]

0
crmpicco (8)
4/5/2006 4:36:24 PM
comp.lang.javascript 38370 articles. 2 followers. javascript4 (1315) is leader. Post Follow

4 Replies
420 Views

Similar Articles

[PageSpeed] 15

crmpicco@aol.com wrote:
> I am trying to delete all 'PiccoOption' nodes that i do not need, i
> then want to put the document, with just one 'PiccoOption' into the
> form field 'document.form.optionNumber.value'.
> This code doesnt seem to work.....
> Any help appreciated.
> [snip]
>
> delNode.removeChild(true);

The XML DOM's removeChild method is slightly different than the regular
HTML DOM one.

Instead of "true" (to remove child nodes from the node to be deleted),
you should pass the node to be deleted as argument.

0
Ronaldo
4/5/2006 8:27:31 PM
I'd like to recommend the use of Sarissa
(http://sarissa.sourceforge.net/doc/), an excellent piece of
cross-browser code for handling XML data.

I believe that you are supposed to call "removeChild()" on the parent
of the node you are trying to delete:

parentNodeObject.removeChild(childNodeObjectToRemove);

But hey, I've been wrong before.

0
addi
4/5/2006 8:29:02 PM
[code]
function loadXML()
{
	var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
	xmlDoc.async="false";
	xmlDoc.loadXML(document.form.optionXML.value);
	var optNo = parseInt(document.form.optionNumber.value); // No need to
make a Float out of this. Integer will suffice.

	if (xmlDoc.documentElement.hasChildNodes)
	{
		var nodes =
xmlDoc.documentElement.getElementsByTagName("VolaroOption") // Let's
make the reference a bit shorter and use an easier method.
		var i=0
		while(nodes.item(i))
		{
			if (i!=optNo)
			{
				//alert("Ref = " +
nodes.item(i).getElementsByTagName("Details").item(0).getElementsByTagName("Ref").item(0).text);
				//alert("i = " + i);
				//alert("optNo = " + optNo);

				xmlDoc.documentElement.childNodes.removeChild(xmlDoc.documentElement.getElementsByTagName("VolaroOption"));
// removeChild takes the child to remove as an argument
			}
			else
			{
				i++ // We only increment i if we have found the node(s) we want to
keep, since the item method will return different children with the
same index if we modify the "nodes" collection.
			}
		}
	}
	//alert(xmlDoc.xml);
	//document.form.optionXML.value=(xmlDoc.xml);
}
[/code]
I tried your suggestion, but it doesnt seem to work.

[quote]
parentNodeObject.removeChild(childNodeObjectToRemove); 
[/quote]

0
crmpicco
4/6/2006 8:24:59 AM
[code]
function loadXML()
{
	var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
	xmlDoc.async="false";
	xmlDoc.loadXML(document.form.optionXML.value);
	var optNo = parseInt(document.form.optionNumber.value); // No need to
make a Float out of this. Integer will suffice.

	if (xmlDoc.documentElement.hasChildNodes)
	{
		var nodes =
xmlDoc.documentElement.getElementsByTagName("PiccoOption") // Let's
make the reference a bit shorter and use an easier method.
		var i=0
		while(nodes.item(i))
		{
			if (i!=optNo)
			{
				//alert("Ref = " +
nodes.item(i).getElementsByTagName("Details").item(0).getElementsByTagName("Ref").item(0).text);
				//alert("i = " + i);
				//alert("optNo = " + optNo);

				//xmlDoc.documentElement.childNodes.removeChild(xmlDoc.documentElement.childNodes.getElementsByTagName("VolaroOption"));
// removeChild takes the child to remove as an argument
				if (xmlDoc.documentElement.childNodes.item(i)!=null)
				{
					xmlDoc.documentElement.removeChild(xmlDoc.documentElement.childNodes.item(i));
					alert("deleted node");
				}
			}
			else
			{
				i++ // We only increment i if we have found the node(s) we want to
keep, since the item method will return different children with the
same index if we modify the "nodes" collection.
			}
		}
	}
	//alert(xmlDoc.xml);
	//document.form.optionXML.value=(xmlDoc.xml);
}
[/code]

this is my function as it is sitting ATM, still seems to give an
error...

any ideas?

0
crmpicco
4/6/2006 8:34:09 AM
Reply:

Similar Artilces:

javascript within a javascript
Hello, I have a multi-frame page. The frames are named Frame_1, Frame_2 and Frame_3. Frame_1 has a drop down box. When a value is selected in this drop down box, Frame_2 is updated using an asp file (as I have to read from a back-end access database). In turn in the asp file, I have a Body onload tag to execute a javascript function within Frame_2. this function updates the contents of Frame_3. Till now this is working fine. Here is the problem. Frame_3 has a form with a radio button. When a radio button is selected, I want that a function be executed in Frame_3. However since conte...

Updating and deleting xml files using javascript
I know how to access parts of an xml file using xpath / xsl. eg tName = "Mr Wallis" var xmlDoc = new ActiveXObject("msxml2.DOMDocument.4.0"); xmlDoc.async=false;xmlDoc.resolveExternals=false;xmlDoc.validateOnParse=fals e; xmlDoc.load("xml/test.xml"); nodes=xmlDoc.selectNodes("/school/teachers[name='" +tName+ "']/*") but what I would like to do is change the name to "Mr Williams" then I would like to delete it Can anyone help or point me towards a tutorial ? Thanks in advance ...

Insert,view,update and delete using javascript and xml
Dear friend, is it possible to implement Insert,view,update and delete using javascript and xml. i would like to do product search in the website which is burnt in CD nag wrote: > is it possible to implement Insert,view,update and delete using > javascript and xml. IIUC: Yes, search for "DOM" and "XPath". > i would like to do product search in the website which is burnt in CD What do you need "insert", "update" and "delete" for then? <http://jibbering.com/faq/#posting> PointedEars -- Use any version of Microsoft Fron...

Javascript and IE? Javascript and C#?
While my question might be simple, the environment around it is terribly messy and so I will try to keep this clear and simple by only including the relevant code - however, as I will soon suggest, I worry that the problem isnt in what would seem to be the relevant code but instead is lost somewhere in the do-and-donts of the peripheral code. So at the end, i'll try to include all the affected code and you can see if any of its actually relevant. I know there is a lot going on... sorry, but I tried to write this clearly. So here is what I imagine to be relevant. I'm working with a page that uses a very simple javascript function change the style of an <li> element (display=block;). The code is simple...which is why I cant understand my problem. This function is being called by <body onload="fop()"> // Javascript function function fop() { var dropDown = document.getElementById("region"); var firstName = dropDown.name; var fload = document.getElementById(firstName); fload.style.display = "block"; } // This is where it grabs the name value. "View Source" confrims the values work, (eg. name="ZHT") <select name="<%=Request.QueryString("lang")%>" id="region" onchange="selectMenu();"> //This is one of the <li> tags <li class="operatorLI" id="ZHT"> // Later for testing, I tried this (see below) <li class="op...

XML XSL javascript, sorting child node of data island
I've been working on this for over a week now, and just can't get this figured out. Hoping one of you gurus can help me out here. I have an xml data island that I'm representing on an htm page as an expandable menu. Got that working, but now I need to add sorting and searching abilities to the menu. I am hoping to do this with xsl but can't get it to work. Is this because of the way I've formed my xml, having the children within the parent elements? Or is my xml alright but my xsl is mis formed. If you could help me figure out how to simply have xsl sort the list, I'...

XML and javascript
Any way to ruin javascript from inside of a .xml file? (<?xml-script...> or the like) On Mon, 21 Apr 2008 19:30:45 -0700 (PDT), in comp.lang.javascript ChefMo <moshefromsinai@gmail.com> <bdd28bec-5f04-44b9-894a-f7c68c8e0b1c@59g2000hsb.googlegroups.com> wrote: >| Any way to ruin javascript from inside of a .xml file? >| (<?xml-script...> or the like) Alot of people can ruin javascript without the need for xml :-P But seriously, XML is data only therefore can not run scripts. -- ------------------------------------------------------------- jnorthau@yourpantsyaho...

dynamic load javascript from javascript
hi, from here: http://www.activewidgets.com/javascript.forum.6114.15/dynamic-load-javascript-from-javascript.html there is a method to load js from js, e.g. //--------------------------------------------------------------------------------------- var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'snip.js'; document.getElementsByTagName('head')[0].appendChild(script); //--------------------------------------------------------------------------------------- this method works great, but there is a bug(?) when using wit...

JavaScript
Guys, anybody know if is possible "to press" a button linked a javascript function using python? My Firefox send something like that: POST /msgs.aspx TOKEN=B8B83BGDBC191B9FE0A0BE1393294FAB&sig=gpaiOqbp0Nr %2BoecRLF4FGGDOAao %3D&toUserId=1331299&rawAddedDate=1188546666&fromUserId=23029&Action.delete=Send +data python has modules for forms and other things... and for it? Thank you for help... zowtar >python has modules for forms and other things... and for it? Check out httplib and urlib2, it might be useful for you. Hi! I know "how to", but o...

javascript
Hi all I wounder if some one can help me i have to write a program that sums numbe3rs together using a for loop. The numbers are 1 to 10 then one to 20 then 1 to 10,000. // A program for summing numbers from one to biggestNumber Var biggestNumber; Var theSum = 0; its got to start like this. Im having problems with this one viicki -- v davies Message posted via JavaKB.com http://www.javakb.com/Uwe/Forums.aspx/java-tools/200512/1 On Fri, 16 Dec 2005 11:27:29 GMT, "vicki via JavaKB.com" <u16404@uwe> wrote, quoted or indirectly quoted someone who said : >// A program fo...

JavaScript
Javascript has it's own significance Amit Patel wrote: > Javascript has it's own significance Mr Patel, Stop using that stuff, it's bad for your brains. :P "Amit Patel" <amit2749@hotmail.com> wrote in message news:5f04ccb8.0401210427.3f93300c@posting.google.com... | Javascript has it's own significance It also has it's own group.. news:comp.lang.javascript ...

JavaScript
If I have Options/ViewingMail/AllowExecutables unchecked does Eudora strip out the JavaScript? Or just refuse to execute it? TIA... Bob "Bob Bailey" <ebiz@usa.net> wrote in message news:rfOdnaRVycZZNzXenZ2dnUVZ_v-dnZ2d@rcn.net... > If I have Options/ViewingMail/AllowExecutables unchecked does Eudora strip > out the JavaScript? Or just refuse to execute it? OK. I've answered my own question but that begs a new one. (Eudora strips the JS.) Having allowed Executables it only works if I open, not preview, the message and then it insists on ope...

javascript
Cut'n'paste from "my" ticket 202 at www.ecomstation.com as they seem to have come to a halt... :-( ################################ Recenty I went from w4 fp17 to eCS 1.2. I get the odd behavior described beneath. Both boxes sees, and uses the same installations and user profiles. Clean install(s) of both Moz and FF has been done several times. Starting FF or Moz clean (no userprofiles), doesn't make any differnce. FIREFOX: The Weather extension i.e doesn't show it's 'mouseover' info, and it refreshes slow. Unit change which ...

Javascript
Hello people, I'm trying to make a regional map in html and javascript, I'm sure how to d= o the following: to hover over the city, he should change the city's image with another clea= rer, and clicking in the city he should get a darker color than the picture= when we hover. Until there all right, but when I click it gets darker image and move the m= ouse in another city he immediately removes the dark image and return to th= e clearer picture. How to keep the image when I click on it and still the effect of passing th= e mouse? --------------------- the other t...

Validating xml file against xml schema using javascript
Hi All, I am trying to take an xml file as input from user and update the sql database with this new data from the xml file. Before going to the step of updating the data in the database, i want to validate this xml file with the xml schema file that i have, to make sure that the user has indeed provided a correctly formed xml, and that the schema of the xml is correct. Now i have searched for some examples as i am new to working with xml files, all i get is samples for .net (xmlvalidatingreader). Can you please give me samples that can be used in asp (not asp.net please) using javascrip...

Nixing Javascript via javascript: pseudoproto?
This is a question about defensive web browsing. Ocassionally I run into a page whose JavaScript does something that I find obnoxious. I would like to turn off JavaScript only for that page (instead of disabling it globally). It would be cool if there were some way to do this through a "bookmarkable" JavaScript snippet using the javascript: pseudoprotocol. Does anyone know any trick to do any of this? Many thanks! -bill "bill" wrote > This is a question about defensive web browsing. Ocassionally I > run into a page whose JavaScript does something that I fi...

Removing JavaScript from the document.
Hi everyone. I would like to know if it's possible to clean up my scripts, or if you will, 'make them biodegradable'. Some of my smaller script will be download to the users browser, but I would like to clear them once I am done, so as not to bog down the browser more than needed. I have tried removing the script element, and/or setting the src attribute to null and '', but the script itself still remains. Here is some example code. <head> <script id="remove_me" type="text/javascript"> function foo(){ alert("bar!"); } ...

assigning session a javascript value in javascript function
Hello Guyz.. I want to assign a varascript value to a session object in javascript function... like i have an image and onClick i am calling a function sort_(str).. Now i want to assign this value str to a session object in the same function... I know javascript code is client side and session is on server side.. but is there any way doing that?? function sort_(str) { document.ins_form.elements["Qry"].value = str; //alert(str); document.form1.submit(); } when i click on that image and that function calls everything works fine. but when i click on next to bring more records i c...

XML parser for javascript
Hi Friends, I have to perform a lot of editing of xml data on the client-side(browser), using javascript. (before i display the data on the browser). Which xml parser is better for accessing and editing xml elements/attributes through javascript code. Greetings, Jagdishwar. jagsmiles@gmail.com wrote: > Hi Friends, > > I have to perform a lot of editing of xml data on the > client-side(browser), using javascript. (before i display the data on > the browser). > > Which xml parser is better for accessing and editing xml > elements/attributes through javascript code....

Newbie XML + Javascript
Hi. Does anybody know how to get the text represetation of an XML dom as string within javascript. I created a XML doc with: var doc; doc = document.implementation.createDocument("", "records", null); I'm also able to add elements to the dom, but when I'm finished I need to get the dom as text representation (assigned to a string) so that I can post it back to the server via xmlHttpRequest object. Any ideas how to do this? Thank's. Rregard, Frank. Frank Gruber wrote: > I created a XML doc with: > > var doc; > doc = document.implementat...

javascript confirm delete
Hi, I have an html form with a number of checkboxes that can be checked to delete items. I want to have a javascript alert prompt box to pop up to confirm the delete. I am building my site with javascript as an enhancement and not a requirement to work. My question is can I have the html form function normally if the user has javascript disabled? It would act as thought there were no javascript code involved in the form at all then. Thanks, John On Mon, 01 Nov 2004 22:53:57 -0600, neoconwannabe wrote: > I have an html form with a number of checkboxes that can be checked ...

Including a javascript relative to its own location from another javascript
Hello, I want to include a javascript from another javascript. I know that I can do that by document.write("<script src='another.js'>"); I am exposing my main.js (which contains the above code) directly, intending it to be used via cross-site scripting (xss). In this case, the above code doesn't work. Because an external html which is using my main.js will look for another.js in its local directory. I have to change 'another.js' to '<absolute path>/another.js' for it to work. But now if I change the location of main.js I have to make chang...

remove javascript from HTML
Hi, I've got a big string with some arbitrarily ugly HTML inside. I need to strip every trace of javascript off the HTML, which means that: <script src="pippo.js"> or <script src="pippo.js" /> or <script language="javascript1.1" src="pippo.js"> or <script> alert('Hello!'); </script> has got to go! What's the best way to achieve this? RegExps? Tricks with StringTokenizer? I am playing with the idea of looping on a StringBuffer and build my own char-by-char logic... ideas? thanks Luca On 13 May 2005 08:48:51 -0700, "luca" <passani@eunet.no> wrote: > >Hi, > >I've got a big string with some arbitrarily ugly HTML inside. >I need to strip every trace of javascript off the HTML, which means >that: [SNIP] Try HTML Tidy. -- now with more cowbell I need to do it programmatically and in Java. HTML Tidy is a command-line utility and it's developed in C. Am I missing something ? Luca On 13 May 2005 11:08:34 -0700, "luca" <passani@eunet.no> wrote: > >I need to do it programmatically and in Java. HTML Tidy is a >command-line utility and it's developed in C. >Am I missing something ? Nope. I missed the part where you said you needed to do it programmatically... -- now with more cowbell "luca" <passani@eunet.no> writes: > Hi, > > I've got a big string with ...

XML and Javascript Question
Is there a Javascript command that will parse an xml tag and then simply output the result right backing the <script> code block? I would like to use this to help populate my "You Are Here" status block on the following page: http://www.gogogulfcoast.com/go.asp?action=state&state=AL Thx, Mark GoGoGulfcoast.com said the following on 2/17/2008 8:59 PM: > Is there a Javascript command that will parse an xml tag and then > simply output the result right backing the <script> code block? I > would like to use this to help populate my "You Are Here" s...

Delete Javascript function
Hi I'm creating now a site which is using heavly AJAX and what comes with it, many Javascript functions are used. However many of these functions are used only once (mainly to load new content by sending request to server and by using DOM editing site content based on the response). So keeping these functions in memory, while new content with new functions is loaded, would be just wasting of memory. And here goes my question - is there any way to delete Javascript functions or free memory used by them? I've tried with "delete" operator but it doesn't work with function...

Web resources about - delete/remove node from XML with JavaScript - comp.lang.javascript

JavaScript Kit- Your comprehensive JavaScript, DHTML, CSS, and Ajax stop
Your comprehensive JavaScript, DHTML, CSS, and Ajax stop

Let's Code: Test-Driven Javascript by James Shore — Kickstarter
James Shore is raising funds for Let's Code: Test-Driven Javascript on Kickstarter! A screencast series focusing on rigorous, professional Javascript ...

Eloquent JavaScript: A Modern Introduction to Programming
... and pragmatics. I loved the tutorial-style game-like program development. This book rekindled my earliest joys of programming. Plus, JavaScript! ...

Lightbox (JavaScript) - Wikipedia, the free encyclopedia
On a Lightbox-enabled page, a user can click an image to have it magnified in a Lightbox window, which resizes itself according to the size of ...

Open Directory - Computers: Programming: Languages: JavaScript: Tools: Obfuscators
about dmoz - help Top : Computers : Programming : Languages : JavaScript : Tools : Obfuscators Tools for obfuscation/compression JavaScript code. ...

Facebook Open-Sources JavaScript Static-Type Checker Flow
The latest software to be open-sourced by Facebook is Flow , a static-type checker for JavaScript . (more…) New Career Opportunities Daily: ...

Under the Hood: The JavaScript SDK - The use of polyfills - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Under the Hood: The JavaScript SDK - The use of polyfills geschrieben. Du kannst den vollständigen ...

Quickstart: Facebook SDK for JavaScript
This quickstart will show you how to setup the SDK, load social plugins, trigger a dialog, and get it to make some basic Graph API calls.

Facebook App Devs Get Javascript
It has been an oft-lamented fact of the Facebook Platform thus far in its life that, in order to use all but the most simple of Javascript functionality–the ...

Badass JavaScript (@badass_js) on Twitter
WebGLWorker is an open source library that allows using WebGL from Web Workers. Great work as always from @kripken . blog.mozilla.org/research/2014/… ...

Resources last updated: 3/12/2016 6:47:48 AM