English 中文(简体)
利用XMLTextWriter VB.net 制作XML
原标题:Looping checkboxlist and create XML using XMLTextWriter VB.net

我是一位名叫xml和net的开端人。 我有一系列检查箱,我希望根据用户选择编制Xml文档。 我希望Xml文档也这样做。

<?xml version="1.0" encoding="utf-8"?>
  <FILTER xmlns:x="urn:1">
    <CATEGORY Name="Year">
      <SELECTED Value="2011/2010" />
      <SELECTED Value="2010/2009" />
      <SELECTED Value="2009/2008" />
    </CATEGORY>
    <CATEGORY Name="Grade">
      <SELECTED Value="Kindergarten 1" />
    </CATEGORY>   
  </FILTER>

但我只想这样做。

<?xml version="1.0" encoding="utf-8"?>
  <FILTER xmlns:x="urn:1">
    <CATEGORY Name="Year">
      <SELECTED Value="2011/2010" />
    </CATEGORY>
    <CATEGORY Name="Year">
      <SELECTED Value="2010/2009" />
    </CATEGORY>
    <CATEGORY Name="Year">
      <SELECTED Value="2009/2008" />
    </CATEGORY>
    <CATEGORY Name="Grade">
      <SELECTED Value="Kindergarten 1" />
    </CATEGORY>
  </FILTER>

这是用于制造Xml文档的VB代码。 请告诉我我我什么是失踪的。 非常感谢帮助。

Dim itemacademicyear As ListItem
Dim itemgrade As ListItem

Dim w As New XmlTextWriter(Server.MapPath("items.xml"), Encoding.UTF8)
w.Formatting = Formatting.Indented
w.WriteStartDocument()
w.WriteStartElement("FILTER")
w.WriteAttributeString("xmlns", "x", Nothing, "urn:1")

For Each itemacademicyear In cblacademicyear.Items
  If itemacademicyear.Selected = True Then
    lblselected.Text = lblselected.Text & itemacademicyear.Text & "&nbsp;" & "<a href= # >remove</a>" & "<BR>"

     xml bit
    w.WriteStartElement("CATEGORY")
    w.WriteAttributeString("Name", "Year")
    w.WriteStartElement("SELECTED")
    w.WriteAttributeString("Value", itemacademicyear.Text)
    w.WriteEndElement()
    w.WriteEndElement()
  End If
Next
最佳回答

3. 您需要将创建你的类别要素移出处:

w.WriteStartElement("CATEGORY")
w.WriteAttributeString("Name", "Year")

For Each itemacademicyear In cblacademicyear.Items
    If itemacademicyear.Selected = True Then
        lblselected.Text = lblselected.Text & itemacademicyear.Text & "&nbsp;" & "<a href= # >remove</a>" & "<BR>"

         xml bit
        w.WriteStartElement("SELECTED")
        w.WriteAttributeString("Value", itemacademicyear.Text)
        w.WriteEndElement()

    End If
Next

w.WriteEndElement()
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签