Solved

write to xml asp.net

Posted on 2009-06-30
10
380 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
  • 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
 
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

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

Accepted Solution

by:
jinal earned 500 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now