Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


HELP ME TO ADD A NEW RECORD TO XML FILE with VBscript?

 
Logged in as: Guest
arrSession:exec spGetSession 2,3,29852
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> ASP >> HELP ME TO ADD A NEW RECORD TO XML FILE with VBscript?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 HELP ME TO ADD A NEW RECORD TO XML FILE with VBscript? - 1/13/2006 3:25:00 AM   
  sreenivas2k

 

Posts: 4
Score: 0
Joined: 1/13/2006
Status: offline
Original message moved by mbouchard
Reason : Moving to correct forum, also, to some, all caps = shouting.
Thanx in advance..........
i want to add a new recordto existing xml file in a specific place.
i tried but i dont find bugs but i didnt get out put please check the code below and let ne know the fault

THE XML FILE(menu1.xml) IS:
<?xml version="1.0"?><menu><menu name="News"><item name="Current News" variables="page.asp?sec=News&amp;page=Current News" action="gotoURL"/></menu>
<menu name="Staff"><item name="Teaching Staff" variables="page.asp?sec=Staff&amp;page=Teaching Staff" action="gotoURL"/></menu></menu>


ASP VBSCRIPT IS:

<%Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = False
xmlDoc.load(Server.MapPath("menu1.xml"))
Set fieldName = xmlDoc.createElement("item")
Set attID = xmlDoc.createAttribute("name")
Set attID1 = xmlDoc.createAttribute("action")
Set attID2 = xmlDoc.createAttribute("variables")
attID.Text =  "News NIGHT"
attID1.Text = "gotoURL"
attID2.Text = "page.asp?sec="+attID.Text+"&page="+"updates"
fieldName.setAttributeNode attID fieldName.setAttributeNode attID1
fieldName.setAttributeNode attID2
for each x in xmlDoc.selectNodes("menu")
if x.getAttribute("name")="News" Then
p=x.firstChild
xmlDoc.insertBefore p,fieldName
end If next
xmlDoc.Save("menu1.xml")%>


if every thing goes right i supposed to get xml file like

<?xml version="1.0"?><menu><menu name="News"><item name="Current News" variables="page.asp?sec=News&amp;page=Current News" action="gotoURL"/><item name="News Night" variables="page.asp?sec=News Night&amp;page=updates" action="gotoURL"/></menu>
<menu name="Staff"><item name="Teaching Staff" variables="page.asp?sec=Staff&amp;page=Teaching Staff" action="gotoURL"/></menu></menu>


but i didnt get out but please help me out

< Message edited by sreenivas2k -- 1/13/2006 3:30:31 AM >


_____________________________

s
 
 
Post #: 1
 
 RE: HELP ME TO ADD A NEW RECORD TO XML FILE with VBscript? - 1/13/2006 7:19:23 AM   
  ebgreen


Posts: 5070
Score: 31
Joined: 7/12/2005
Status: online
Well if it is not just a copy and paste problem, then this line is invalid:

fieldName.setAttributeNode attID fieldName.setAttributeNode attID1

It would need to be two lines or have a line seperator:

fieldName.setAttributeNode attID
fieldName.setAttributeNode attID1

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to sreenivas2k)
 
 
Post #: 2
 
 RE: HELP ME TO ADD A NEW RECORD TO XML FILE with VBscript? - 1/13/2006 7:29:01 AM   
  ebgreen


Posts: 5070
Score: 31
Joined: 7/12/2005
Status: online
I reformatted your input XML so I could see it better and I noticed that your root Node is named the same thing as it's children. I can't point to a specific XML rule that this validates but it seems hinky to me. Here is the formatted XML if anyone wants it:

      

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: HELP ME TO ADD A NEW RECORD TO XML FILE with VBscript? - 1/13/2006 7:36:35 AM   
  ebgreen


Posts: 5070
Score: 31
Joined: 7/12/2005
Status: online
Also I think you may need to a Server.MapPath when you save the XML file. Another syntax error is this line

end if next

which needs to be split:

end if
next

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ebgreen)
 
 
Post #: 4
 
 RE: HELP ME TO ADD A NEW RECORD TO XML FILE with VBscript? - 1/13/2006 7:40:36 AM   
  ebgreen


Posts: 5070
Score: 31
Joined: 7/12/2005
Status: online
EDIT: Ignore this one....I found the right name attribute.


The next thing I see is that the condition you check for is If x.getAttribute("name")="News". Well since none of your nodes have a "name" attribute that equals "News", then the new node will never be inserted.

< Message edited by ebgreen -- 1/13/2006 7:57:02 AM >


_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: HELP ME TO ADD A NEW RECORD TO XML FILE with VBscript? - 1/13/2006 8:11:40 AM   
  ebgreen


Posts: 5070
Score: 31
Joined: 7/12/2005
Status: online
This code should work as long as you change the root node to be named something other than what it's children are named (in this case I chose root).


      

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ebgreen)
 
 
Post #: 6
 
 RE: HELP ME TO ADD A NEW RECORD TO XML FILE with VBscript? - 1/15/2006 10:22:02 PM   
  sreenivas2k

 

Posts: 4
Score: 0
Joined: 1/13/2006
Status: offline
Thanx mate it works
.........................................................................
so happy to meet u .........................
                 thanks vermuch for helping out...................

_____________________________

s

(in reply to ebgreen)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> ASP >> HELP ME TO ADD A NEW RECORD TO XML FILE with VBscript? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts