Read Xml nodes using XmlDocument without namespace

  Kiến thức lập trình

I need to parse and read an xml using vb.net 4.0 XmlDocument, the problem is that xml does not have namespace, I have a working code which uses XElement, but need to use XmlDocument and can’t import Xml.Linq so XElement is not an option for me:

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() = [email protected]()
R = Single.Parse(Components(0).Substring(2))
G = Single.Parse(Components(1).Substring(2))
B = Single.Parse(Components(2).Substring(2))
EName = MyXElement.@OPFCategoryCopyName

And here’s my Xml:

<?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>

Now, if I use XmlDocument Load/LoadXml how can I obtain elementCount number and OPFCategoryCopyBackgroundColor/OPFCategoryCopyName?

Any tip or help is greatelt appreciated.
Thanks in advance.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT