Hello
When parsing this kind of xml, I need to get the number of elementCount and the following 2 fields:
OPFCategoryCopyBackgroundColor
OPFCategoryCopyName
Here's my working code:
Dim MyXML As XElement = XElement.Load(MemoryStream)
Dim count As Integer = Integer.Parse(MyXML.@elementCount)
For Each MyXElement As XElement In MyXML.Elements
Dim Components As String() = MyXElement.@OPFCategoryCopyBackgroundColor.Split()
R = Single.Parse(Components(0).Substring(2))
G = Single.Parse(Components(1).Substring(2))
B = Single.Parse(Components(2).Substring(2))
EName = MyXElement.@OPFCategoryCopyName
Is it possible to obtain the above 3 fields using XmlDocument rather than XElement?
Xml sample:
<?xml version="1.0" encoding="utf-8"?>
<categories elementCount="18">
<category xml:space="preserve" OPFCategoryCopyBackgroundColor="r:0.57 g:0.48 b:0.82" OPFCategoryCopyName="Birthday"></category>
<category xml:space="preserve" OPFCategoryCopyBackgroundColor="r:0.45 g:0.60 b:0.88" OPFCategoryCopyName="Blue category"></category>
<category xml:space="preserve" OPFCategoryCopyBackgroundColor="r:0.92 g:0.79 b:0.40" OPFCategoryCopyName="Brown Category"></category>
<category xml:space="preserve" OPFCategoryCopyBackgroundColor="r:0.63 g:0.26 b:0.80" OPFCategoryCopyName="Family"></category>
</categories>
Thanks in advance :)
For Each el As XmlNode In doc.SelectNodes("/categories/category")
MsgBox(el.Attributes.GetNamedItem("OPFCategoryCopyBackgroundColor").Value)
Next
The only question, both following codes will work:
el.Attributes.GetNamedItem("OPFCategoryCopyBackgroundColor").Value
vs
el.Attributes("OPFCategoryCopyBackgroundColor").Value
So which one is safer or recommended to use?
Thanks :)