|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi all,
This is 'manage_accounts.xml' file: <?xml version = "1.0"?> <MANAGE_ACCOUNTS> <USER > <USERNAME>a</USERNAME> <PASSWORD>a</PASSWORD> </USER> <USER > <USERNAME>b</USERNAME> <PASSWORD>b</PASSWORD> </USER > <USER > <USERNAME>c</USERNAME> <PASSWORD>c</PASSWORD> </USER > </MANAGE_ACCOUNTS> i want to remove node USER and it's content if i enter 'username' in textbox == 'username' in one node: for ex: enter "b" -> remove node USER which contain user b result must be: <?xml version = "1.0"?> <MANAGE_ACCOUNTS> <USER > <USERNAME>a</USERNAME> <PASSWORD>a</PASSWORD> </USER> <USER > <USERNAME>c</USERNAME> <PASSWORD>c</PASSWORD> </USER > </MANAGE_ACCOUNTS> this is my script to do this: <script language = "javascript"> <XML ID="customers" SRC = "manage_accounts.xml"></XML> function delete_user() { var input = remove_form.txtUsername.value.toLowerCase(); var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.load("manage_accounts.xml") customers.recordset.moveFirst(); while (!customers.recordset.EOF) { var currentUserName = new String(customers.recordset("USERNAME")) //change to lowercase currentUserName = currentUserName.toLowerCase(); if(input == currentUserName) { var remove_node = xmlDoc.selectSingleNode("/MANAGE_ACCOUNTS/USER") xmlDoc.documentElement.removeChild(remove_node) } customers.recordset.moveNext(); }//end of while (!customers.recordset.EOF) } </script> but when i enter "a"or "b"or"c"-> it's alway delete the first node result alway is: <?xml version = "1.0"?> <MANAGE_ACCOUNTS> <USER > <USERNAME>b</USERNAME> <PASSWORD>b</PASSWORD> </USER > <USER > <USERNAME>c</USERNAME> <PASSWORD>c</PASSWORD> </USER > </MANAGE_ACCOUNTS> i don't know how to solve this problem? please help me, it's in urgent! Thanks a lot.. |
|
#2
|
|||
|
|||
|
Try something like:
Code:
var remove_node = xmlDoc.selectSingleNode("/MANAGE_ACCOUNTS/USER[USERNAME='" + input + "']")
xmlDoc.documentElement.removeChild(remove_node)
|
|
#3
|
|||
|
|||
|
YES, thank you very much mr. Bricker42!
it's work greate! Thanks again.. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > remove one node in xml??? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|