[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

write to xml asp.net

Posted on 2009-06-30
10
Medium Priority
?
388 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
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.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

656 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