私のアプリはXMLを作成できるようになり、Element 'Osiguranikも無制限に入力できます。VB.NET XMLシリアライゼーション3番目の子エレメントを繰り返します。
今、私は要素 'Usluge'を無制限に入力したいが、この要素: 'Usluge'はElement: 'Osiguranik'にある。 'Osiguranik' と私はulimitedエントリを作成することができます:私は要素のためのボタンがあり
<?xml version="1.0" encoding="utf-8"?>
<Faktura>
<Ustanova>
<Name>Test1</Name>
<LName>Test3</LName>
<Age>Test4</Age>
</Ustanova>
<Osiguranik>
<Fil>Test3</Fil>
<Isp>Test4</Isp>
<Prez>Test5</Prez>
<DodatneDijagnoze>
<DDijag>50</DDijag>
<Usluge>
<DatUsl>1</DatUsl>
<SifUsl>10</SifUsl>
</Usluge>
</DodatneDijagnoze>
</Osiguranik>
</Faktura>
:ここ
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization
Public Class Form1
Dim faktura As New Faktura
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'This button add Ustanova again
faktura.Ustanova.Add(New Ustanova() With {.Age = txtIsp.Text, .LName = txtFil.Text, .Name = txtName.Text})
txtName.Text = ""
txtLName.Text = ""
txtAge.Text = ""
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
'Here I create XML
Dim ns As New XmlSerializerNamespaces()
Dim objStreamWriter As New StreamWriter("Invoice.xml") ' in the build folder
Dim x As New XmlSerializer(faktura.GetType)
ns.Add("", "")
x.Serialize(objStreamWriter, faktura, ns)
objStreamWriter.Close()
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
'This button add Osiguranik again
faktura.Osiguranik.Add(New Osiguranik() With {.Fil = txtFil.Text, .Isp = txtIsp.Text, .Prez = txtPrez.Text, .DodatneDijagnoze = New DDijag() With {.DDijag = txtDDijag.Text}})
txtFil.Text = ""
txtIsp.Text = ""
txtPrez.Text = ""
txtDDijag.Text = ""
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
' Here I want when click "Insert" to add Element 'Usluge' again.
End Sub
End Class
<XmlRoot(ElementName:="Ustanova")>
Public Class Ustanova
<XmlElement(ElementName:="Name")>
Public Property Name() As String
Get
Return m_Name
End Get
Set
m_Name = Value
End Set
End Property
Private m_Name As String
<XmlElement(ElementName:="LName")>
Public Property LName() As String
Get
Return m_LName
End Get
Set
m_LName = Value
End Set
End Property
Private m_LName As String
<XmlElement(ElementName:="Age")>
Public Property Age() As String
Get
Return m_Age
End Get
Set
m_Age = Value
End Set
End Property
Private m_Age As String
End Class
<XmlRoot(ElementName:="Osiguranik")>
Public Class Osiguranik
<XmlElement(ElementName:="Fil")>
Public Property Fil() As String
Get
Return m_Fil
End Get
Set
m_Fil = Value
End Set
End Property
Private m_Fil As String
<XmlElement(ElementName:="Isp")>
Public Property Isp() As String
Get
Return m_Isp
End Get
Set
m_Isp = Value
End Set
End Property
Private m_Isp As String
<XmlElement(ElementName:="Prez")>
Public Property Prez() As String
Get
Return m_Prez
End Get
Set
m_Prez = Value
End Set
End Property
Private m_Prez As String
<XmlElement(ElementName:="DodatneDijagnoze")>
Public Property DodatneDijagnoze() As DDijag
Get
Return m_DodatneDijagnoze
End Get
Set(ByVal value As DDijag)
m_DodatneDijagnoze = value
End Set
End Property
Private m_DodatneDijagnoze As DDijag
End Class
<XmlRoot(ElementName:="DDijag")>
Public Class DDijag
Private m_DDijag As String
Public Property DDijag() As String
Get
Return m_DDijag
End Get
Set(ByVal value As String)
m_DDijag = value
End Set
End Property
<XmlElement(ElementName:="Usluge")>
Public Property Usluge() As DatUsl
Get
Return m_Usluge
End Get
Set(ByVal value As DatUsl)
m_Usluge = value
End Set
End Property
Private m_Usluge As DatUsl
End Class
<XmlRoot(ElementName:="DatUsl")>
Public Class DatUsl
Private m_DatUsl As String
Public Property DatUsl() As String
Get
Return m_DatUsl
End Get
Set(ByVal value As String)
m_DatUsl = value
End Set
End Property
<XmlElement(ElementName:="SifUsl")>
Public Property SifUsl() As String
Get
Return m_SifUsl
End Get
Set
m_SifUsl = Value
End Set
End Property
Private m_SifUsl As String
End Class
<XmlRoot(ElementName:="Faktura")>
Public Class Faktura
Sub New()
Me.Ustanova = New List(Of Ustanova)
Me.Osiguranik = New List(Of Osiguranik)
End Sub
<XmlElement(ElementName:="Ustanova")>
Public Property Ustanova() As List(Of Ustanova)
Get
Return m_Ustanova
End Get
Set
m_Ustanova = Value
End Set
End Property
Private m_Ustanova As List(Of Ustanova)
<XmlElement(ElementName:="Osiguranik")>
Public Property Osiguranik() As List(Of Osiguranik)
Get
Return m_Osiguranik
End Get
Set
m_Osiguranik = Value
End Set
End Property
Private m_Osiguranik As List(Of Osiguranik)
End Class
がどのように見えるかXMLです:
は、ここに私のコードです。
私は要素のためのボタンを作る必要があります:無制限の入力のための 'Usluge'。
を開始するためのテンプレートとしてこの新しいコードを使用することができます.org/r321y3en3/Problem.png –
Public Class F_Child ....がコードに含まれていることを確認してください(そのスクリーンショットからは見ることができません)。 – Monty
このコードは2つのエントリしか作成できません。メモを残すボタンでプロジェクトにコードを追加するだけですか?プロジェクトを見て、どこにコードを追加してください。私はXMLを作成する2日間を失ったし、もう一度何もする必要はありません。プロジェクト:mediafire.com/download/hpv8u0kb96ptkuw/XML-Writer.zip –