D
DPG net
Guest
Hello,
Im using vs2013 and want to store many numbers (Serial numbers) in an XML structure like a database.
The Idea is to introduce a number like that:
<?xml version="1.0"?>
<ROOT>
<_4>
<_6>
<_8>
<_1 />
</_8>
</_6>
</_4>
</ROOT>
This will be 4681 for exemple. I add an "_" why a marker cant be only a number. In the same XML if I introduce 5325 it will appear like:
<?xml version="1.0"?>
<ROOT>
<_4>
<_6>
<_8>
<_1 />
</_8>
</_6>
</_4>
<_5>
<_3>
<_2>
<_5 />
</_2>
</_3>
</_5>
</ROOT>
If I add 5389 it must appear like:
<?xml version="1.0"?>
<ROOT>
<_4>
<_6>
<_8>
<_1 />
</_8>
</_6>
</_4>
<_5>
<_3>
<_2>
<_5 />
</_2>
<_8>
<_9 />
</_8>
</_3>
</_5>
</ROOT>
Then, my code in this momento is:
If Not ExistNodeInXml(xdDoc, SN_Node) Then In SN_Node the I put the whole String, ex. "/_4/_9/_3/_9"
Dim xnRoot As XmlElement = xdDoc.DocumentElement
Dim SN_PartNode As String = ""
NodeExist = True
FirstNodeCheked = False
For I = CONST_DigitFile + 1 To Len(v_SN)
FirstNodeCheked = True
SN_PartNode += "/" & M & Mid(v_SN, I, 1)
If Not ExisteNodeEnXml(xdDoc, SN_PartNode) Then If we dont find the whole node, then I will try to find if its some part: first /_4, if it exist /_4/_9 and on the other case I add every part of the node.
If Len(SN_PartNode) > 3 Then Its to be sure that SN_PartNode isnt empty
If NodeExist Then
Dim aa As Int32 = 0
End If
Dim xeMainElement As XmlElement = xnRoot.SelectSingleNode("./" & Mid(SN_PartNode, 1, Len(SN_PartNode) - 3))
Dim xeSubElement As XmlElement
xeSubElement = xdDoc.CreateElement(M & Mid(v_SN, I, 1).ToString)
xeMainElement.AppendChild(xeSubElement)
Else
NodeExist = False
Dim xeSubElement As XmlElement
xeSubElement = xdDoc.CreateElement(M & Mid(v_SN, I, 1).ToString)
xnRoot.AppendChild(xeSubElement)
End If
End If
Next
Dim xtwWriter As New XmlTextWriter(v_FileName, Nothing)
xtwWriter.Formatting = Formatting.Indented
xdDoc.Save(xtwWriter)
xtwWriter.Close()
Return v_SN
End If
Private Function ExistNodeInXml(ByVal xdDoc As XmlDocument, ByVal v_Node As String) As Boolean
Dim root As XmlElement = xdDoc.DocumentElement
Dim keyNode As XmlNode = root.SelectSingleNode("/" & v_Node)
If keyNode Is Nothing Then
Return False
Else
Return True
End If
End Function
The problema is that I need to specify at what level It must find the Node. If I Find the _5 node for the first level and it find it at the third level it send me a true. How to check the level? I say level thats for exemple in "/_4/_9/_3/_9" I find /_4 for the first level and If in the XML it find before a node like /_2/_9/_4/_9 It select it also and for me its the third level.
The point is also to find it quicker as possible. I know, Im starting to use XML and I really need some help.
Thanks very much,
David
David
Continue reading...
Im using vs2013 and want to store many numbers (Serial numbers) in an XML structure like a database.
The Idea is to introduce a number like that:
<?xml version="1.0"?>
<ROOT>
<_4>
<_6>
<_8>
<_1 />
</_8>
</_6>
</_4>
</ROOT>
This will be 4681 for exemple. I add an "_" why a marker cant be only a number. In the same XML if I introduce 5325 it will appear like:
<?xml version="1.0"?>
<ROOT>
<_4>
<_6>
<_8>
<_1 />
</_8>
</_6>
</_4>
<_5>
<_3>
<_2>
<_5 />
</_2>
</_3>
</_5>
</ROOT>
If I add 5389 it must appear like:
<?xml version="1.0"?>
<ROOT>
<_4>
<_6>
<_8>
<_1 />
</_8>
</_6>
</_4>
<_5>
<_3>
<_2>
<_5 />
</_2>
<_8>
<_9 />
</_8>
</_3>
</_5>
</ROOT>
Then, my code in this momento is:
If Not ExistNodeInXml(xdDoc, SN_Node) Then In SN_Node the I put the whole String, ex. "/_4/_9/_3/_9"
Dim xnRoot As XmlElement = xdDoc.DocumentElement
Dim SN_PartNode As String = ""
NodeExist = True
FirstNodeCheked = False
For I = CONST_DigitFile + 1 To Len(v_SN)
FirstNodeCheked = True
SN_PartNode += "/" & M & Mid(v_SN, I, 1)
If Not ExisteNodeEnXml(xdDoc, SN_PartNode) Then If we dont find the whole node, then I will try to find if its some part: first /_4, if it exist /_4/_9 and on the other case I add every part of the node.
If Len(SN_PartNode) > 3 Then Its to be sure that SN_PartNode isnt empty
If NodeExist Then
Dim aa As Int32 = 0
End If
Dim xeMainElement As XmlElement = xnRoot.SelectSingleNode("./" & Mid(SN_PartNode, 1, Len(SN_PartNode) - 3))
Dim xeSubElement As XmlElement
xeSubElement = xdDoc.CreateElement(M & Mid(v_SN, I, 1).ToString)
xeMainElement.AppendChild(xeSubElement)
Else
NodeExist = False
Dim xeSubElement As XmlElement
xeSubElement = xdDoc.CreateElement(M & Mid(v_SN, I, 1).ToString)
xnRoot.AppendChild(xeSubElement)
End If
End If
Next
Dim xtwWriter As New XmlTextWriter(v_FileName, Nothing)
xtwWriter.Formatting = Formatting.Indented
xdDoc.Save(xtwWriter)
xtwWriter.Close()
Return v_SN
End If
Private Function ExistNodeInXml(ByVal xdDoc As XmlDocument, ByVal v_Node As String) As Boolean
Dim root As XmlElement = xdDoc.DocumentElement
Dim keyNode As XmlNode = root.SelectSingleNode("/" & v_Node)
If keyNode Is Nothing Then
Return False
Else
Return True
End If
End Function
The problema is that I need to specify at what level It must find the Node. If I Find the _5 node for the first level and it find it at the third level it send me a true. How to check the level? I say level thats for exemple in "/_4/_9/_3/_9" I find /_4 for the first level and If in the XML it find before a node like /_2/_9/_4/_9 It select it also and for me its the third level.
The point is also to find it quicker as possible. I know, Im starting to use XML and I really need some help.
Thanks very much,
David
David
Continue reading...