Среда Visual Basic STUDIO’2010 Professional
В следующем примере (он без ошибок!) кода показано, как получить
коллекцию атрибутов и пройти по ней, используя метод Count для индекса
цикла. Затем в примере демонстрируется получение одного атрибута
из коллекции и вывод его значения.
Как записать строку doc2.LoadXml(" . . . ) для чтения
информации из файла "data.xml", в котором одинаковое содержимое?
doc2.LoadXml(data.xml) - так нельзя!
doc2.Load("c:\data.xml") - так тоже НЕПРАВИЛЬНО
Dim doc2 As XmlDocument = New XmlDocument()
doc2.LoadXml("<book genre='novel' ISBN='1-861001-57-5' misc='sale item'>" & _
"<title>The Handmaid's Tale</title>" & _
"<price>14.95</price>" & _
"</book>")
' Move to an element.
Dim myElement As XmlElement = doc2.DocumentElement
' Create an attribute collection from the element.
Dim attrColl As XmlAttributeCollection = myElement.Attributes
' Show the collection by iterating over it.
' РЕЗУЛЬТАТ выводится в ОКНО ВЫВОДА
Console.WriteLine("1.Display all the attributes in the collection...")
Dim i As Integer
For i = 0 To attrColl.Count - 1
Console.Write("{0} = ", attrColl.ItemOf(i).Name)
Console.Write("{0}", attrColl.ItemOf(i).Value)
Console.WriteLine()
Next
' Retrieve a single attribute from the collection; specifically, the
' attribute with the name "misc".
Dim attr As XmlAttribute = attrColl("misc")
' Retrieve the value from that attribute.
Dim miscValue As String = attr.InnerXml
Console.WriteLine("2.Display the attribute information.")
Console.WriteLine(miscValue)


