Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CreateElement Questions

10 views
Skip to first unread message

sumi...@gmail.com

unread,
Oct 15, 2012, 4:19:40 PM10/15/12
to
Hello - I have the following code:

Dim xmlfile As New ConfigXmlDocument
'loading our xmal
xmlfile.Load(Server.MapPath("~\xmldata\survey.xml"))

'creating tages
Dim theSurveyTag As XmlElement = xmlfile.CreateElement("Survey")
Dim theTitleTag As XmlElement = xmlfile.CreateElement("Survey_Title")
Dim theLinkTag As XmlElement = xmlfile.CreateElement("Survey_Link")
Dim thePassTag As XmlElement = xmlfile.CreateElement("Survey_Pass")


'create informaiton that goes into the tages
Dim theNameText As XmlText = xmlfile.CreateTextNode(t1.Text)
Dim theEmailText As XmlText = xmlfile.CreateTextNode(t2.Text)
Dim theTelText As XmlText = xmlfile.CreateTextNode(t3.Text)


'append the textnode to elements tages
theTitleTag.AppendChild(theNameText)
theLinkTag.AppendChild(theEmailText)
thePassTag.AppendChild(theTelText)


'appent all the information to the winners tage
theSurveyTag.AppendChild(theTitleTag)
theSurveyTag.AppendChild(theLinkTag)
theSurveyTag.AppendChild(thePassTag)

'now we are going to add thewinnerstag to the document element which is the root element (winnners)
xmlfile.DocumentElement.AppendChild(theSurveyTag)

'now we are going to save the xml file
xmlfile.Save(Server.MapPath("~\xmldata\survey.xml"))

And here is the output

<?xml version="1.0" encoding="utf-8"?>
<!--XML Database.-->
<Data>
<Survey>
<Survey_Title>Demo Survey 3</Survey_Title>
<Survey_Link>http://www.google.com</Survey_Link>
<Survey_Pass>demo3</Survey_Pass>
</Survey>
</Data>


How do I add ID=<some random number> with <Survey node> so output would be:

<?xml version="1.0" encoding="utf-8"?>
<!--XML Database.-->
<Data>
<Survey ID="1">
<Survey_Title>Demo Survey 3</Survey_Title>
<Survey_Link>http://www.google.com</Survey_Link>
<Survey_Pass>demo3</Survey_Pass>
</Survey>
</Data>

Bjoern Hoehrmann

unread,
Oct 15, 2012, 4:35:12 PM10/15/12
to
* sumi...@gmail.com wrote in microsoft.public.xml:
>Dim xmlfile As New ConfigXmlDocument
> 'loading our xmal
> xmlfile.Load(Server.MapPath("~\xmldata\survey.xml"))
>
> 'creating tages
> Dim theSurveyTag As XmlElement = xmlfile.CreateElement("Survey")

>How do I add ID=<some random number> with <Survey node> so output would be:

XmlElement objects have a 'SetAttribute' method for this purpose,
something like `theSurveyTag.SetAttribute('ID', '1')` should do it.
--
Björn Höhrmann · mailto:bjo...@hoehrmann.de · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/

sumi...@gmail.com

unread,
Oct 15, 2012, 4:43:29 PM10/15/12
to
SUPAAAAAAA Thanks!
0 new messages