?
Solved

write to xml asp.net

Posted on 2009-06-30
10
Medium Priority
?
387 Views
Last Modified: 2012-05-07
i want to delete content of existing xml file and then write new data to it. how do i do that in vb.net asp.net thanks.
0
Comment
Question by:StewSupport
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 15

Expert Comment

by:jinal
ID: 24746454
In order to manuplate XML file in ASP.net and VB.net.

Use XmlDocument Class.

you can find example at following link.

http://www.c-sharpcorner.com/UploadFile/mahesh/ReadWriteXMLTutMellli2111282005041517AM/ReadWriteXMLTutMellli21.aspx

0
 
LVL 15

Expert Comment

by:jinal
ID: 24746469
0
 

Author Comment

by:StewSupport
ID: 24746471
and then read this out so you can create a listbox out of this.
<class name ="English" id= "class1">
   <studentinfo id="1">
        <studentname>Anderson</studentname>
        <studentid>1111</studentid>
   </studentinfo>
</class>
i will have multiple class and multiple studentinfo. can you guys help please. thanks.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 15

Expert Comment

by:jinal
ID: 24746492
In which format you want to display this. Or you just want to read this.
0
 

Author Comment

by:StewSupport
ID: 24746862
well i just want to read the xml in the format i gave abve and then put that into a select list
like this

<select ....>
<option group=English>
<option value=studentid>Student name</option>
</select>
0
 

Author Comment

by:StewSupport
ID: 24746982
sorry i want to read and write(create) xml file
0
 
LVL 15

Accepted Solution

by:
jinal earned 2000 total points
ID: 24747082
Dim doc As New XmlDocument
        doc.Load("XMLFile1.xml")

        Dim ele As XmlElement = doc.CreateElement("class")
        Dim class2 As XmlAttribute = doc.CreateAttribute("name")
        Dim id2 As XmlAttribute = doc.CreateAttribute("id")
        class2.Value = "class2"
        id2.Value = "2"
        ele.Attributes.Append(class2)
        ele.Attributes.Append(id2)
        doc.DocumentElement.AppendChild(ele)
        doc.Save("XmlFile1.xml")

XMLFile1.xml

<?xml version="1.0" encoding="utf-8" ?>
<Data>
  <class name ="English" id= "class1">
    <studentinfo id="1">
      <studentname>Anderson</studentname>
      <studentid>1111</studentid>
    </studentinfo>
  </class>  
</Data>
0
 

Author Comment

by:StewSupport
ID: 24747532
this is the format i have
<?xml version="1.0" encoding="utf-8" ?>
<catalog>
  <optgroup label="Bakery">
    <option value="111">Chicken</option>
  </optgroup>
  <optgroup label="BBQ">
    <option value="222">Fried</option>
  </optgroup>
</catalog>
how do i read it so that i would have label in the select list and then value and text in item?

i have this and dont know where to go from there.
 For Each productnode In nodelist
            If productnode.Attributes.Count > 0 Then
                For Each productsubnode In productnode.ChildNodes
                    'add to child list box                    
                    ListBox_Section1.Items.Add(New ListItem(productsubnode.Name.ToString, productsubnode.Value.ToString))
                Next
            End If
        Next
0
 
LVL 15

Expert Comment

by:jinal
ID: 24749090
Dim groupNodes As XmlNodeList = doc.SelectNodes("/catalog/optgroup")
        Dim output As New System.Text.StringBuilder
        output.Append("<Select>")
        For Each node As XmlNode In groupNodes
            output.AppendFormat("<option group=""{0}"" />", node.Attributes(0).Value)
            Dim students As XmlNodeList = node.ChildNodes()
            For Each snode As XmlNode In students
                output.AppendFormat("<option value=""{0}"" >{1}</option>", snode.Attributes(0).Value, snode.InnerText)
            Next
        Next
        output.Append("<Select>")
0
 

Author Comment

by:StewSupport
ID: 24751163
the only thing i got out of your code is <select> <select>
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question