J
Jared
All,
First of all, I have already posted this in the XML newsgroup, but, my
problem does pertain to VB as well so I thought I would post here in hopes
one of you gurus knows my answer. I am very new to XML and I don't follow it
very well, I have a book, and it does provide some insight into my problem
(it may be the cause of it though). I am trying to list the contents of a
file, it is a rather large file in terms of depth (my opinion). I want to be
able to select all the <item> nodes at one time from anywhere in the
document. I have examples, they just don't work. I am open to any
suggestions; thanks.
Jared
I only want the item nodes from this document, it has multiple entry nodes
in it and I want to get their item nodes as well. This is the Code I found
in my book, it works in the books example but not in the history-approve
document. Why?
'Start VB Code
Dim doc As XmlDocument = New XmlDocument
doc.Load("booksort.xml")
Dim book As XmlNode
Dim nodeList As XmlNodeList
Dim root As XmlNode = doc.DocumentElement
nodeList = root.SelectNodes("descendant::book")
Dim str As String
For Each node As XmlNode In nodeList
str += node.InnerText & vbCrLf
Next
MsgBox(str)
Dim xDoc As New XmlDocument
Dim xRoot As Xml.XmlNode
Dim xNodes As Xml.XmlNodeList
xDoc.Load("history-approve.xml")
xRoot = xDoc.DocumentElement
xNodes = xRoot.SelectNodes("descendant::item")
'End VB Code
' History-Approve example
<?xml version="1.0" encoding="UTF-8"?>
<log xmlns="x-schema:ApproveSchema.xml">
<entry loc="en" time="2003-09-09T20:16:04" user="DOMAIN\USERNAME (DISPLAY
NAME)">
<approve>
<startType>manual</startType>
<resultCode>0</resultCode>
<resultText>Success</resultText>
<itemList>
<item>
<title>329170: Security Update (Windows 2000)</title>
<itemID>com_microsoft.329170 Security Update Windows 2000</itemID>
<status>unapproved</status>
<resultCode>0</resultCode>
<resultText>Success</resultText>
</item>
<item>
<title>329170: Security Update</title>
<itemID>com_microsoft.329170 Security Update Windows XP</itemID>
<status>unapproved</status>
<resultCode>0</resultCode>
<resultText>Success</resultText>
</item>
<item>
<title>331953: Security Update (Windows 2000)</title>
<itemID>com_microsoft.331953_W2K_5918</itemID>
<status>unapproved</status>
<resultCode>0</resultCode>
<resultText>Success</resultText>
</item>
<item>
<title>331953: Security Update (Windows XP)</title>
<itemID>com_microsoft.331953_WXP_5919</itemID>
<status>unapproved</status>
<resultCode>0</resultCode>
<resultText>Success</resultText>
</item>
</itemList>
</approve>
</entry>
</log>
'Book Example
<?xml version="1.0"?>
<!-- A fragment of a book store inventory database -->
<bookstore xmlns:bk="urn:samples">
<book genre="novel" publicationdate="1997" bk:ISBN="1-861001-57-8">
<title>Pride And Prejudice</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>24.95</price>
</book>
<book genre="novel" publicationdate="1992" bk:ISBN="1-861002-30-1">
<title>The Handmaid's Tale</title>
<author>
<first-name>Margaret</first-name>
<last-name>Atwood</last-name>
</author>
<price>29.95</price>
</book>
<book genre="novel" publicationdate="1991" bk:ISBN="1-861001-57-6">
<title>Emma</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>19.95</price>
</book>
<book genre="novel" publicationdate="1982" bk:ISBN="1-861001-45-3">
<title>Sense and Sensibility</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>19.95</price>
</book>
</bookstore>
First of all, I have already posted this in the XML newsgroup, but, my
problem does pertain to VB as well so I thought I would post here in hopes
one of you gurus knows my answer. I am very new to XML and I don't follow it
very well, I have a book, and it does provide some insight into my problem
(it may be the cause of it though). I am trying to list the contents of a
file, it is a rather large file in terms of depth (my opinion). I want to be
able to select all the <item> nodes at one time from anywhere in the
document. I have examples, they just don't work. I am open to any
suggestions; thanks.
Jared
I only want the item nodes from this document, it has multiple entry nodes
in it and I want to get their item nodes as well. This is the Code I found
in my book, it works in the books example but not in the history-approve
document. Why?
'Start VB Code
Dim doc As XmlDocument = New XmlDocument
doc.Load("booksort.xml")
Dim book As XmlNode
Dim nodeList As XmlNodeList
Dim root As XmlNode = doc.DocumentElement
nodeList = root.SelectNodes("descendant::book")
Dim str As String
For Each node As XmlNode In nodeList
str += node.InnerText & vbCrLf
Next
MsgBox(str)
Dim xDoc As New XmlDocument
Dim xRoot As Xml.XmlNode
Dim xNodes As Xml.XmlNodeList
xDoc.Load("history-approve.xml")
xRoot = xDoc.DocumentElement
xNodes = xRoot.SelectNodes("descendant::item")
'End VB Code
' History-Approve example
<?xml version="1.0" encoding="UTF-8"?>
<log xmlns="x-schema:ApproveSchema.xml">
<entry loc="en" time="2003-09-09T20:16:04" user="DOMAIN\USERNAME (DISPLAY
NAME)">
<approve>
<startType>manual</startType>
<resultCode>0</resultCode>
<resultText>Success</resultText>
<itemList>
<item>
<title>329170: Security Update (Windows 2000)</title>
<itemID>com_microsoft.329170 Security Update Windows 2000</itemID>
<status>unapproved</status>
<resultCode>0</resultCode>
<resultText>Success</resultText>
</item>
<item>
<title>329170: Security Update</title>
<itemID>com_microsoft.329170 Security Update Windows XP</itemID>
<status>unapproved</status>
<resultCode>0</resultCode>
<resultText>Success</resultText>
</item>
<item>
<title>331953: Security Update (Windows 2000)</title>
<itemID>com_microsoft.331953_W2K_5918</itemID>
<status>unapproved</status>
<resultCode>0</resultCode>
<resultText>Success</resultText>
</item>
<item>
<title>331953: Security Update (Windows XP)</title>
<itemID>com_microsoft.331953_WXP_5919</itemID>
<status>unapproved</status>
<resultCode>0</resultCode>
<resultText>Success</resultText>
</item>
</itemList>
</approve>
</entry>
</log>
'Book Example
<?xml version="1.0"?>
<!-- A fragment of a book store inventory database -->
<bookstore xmlns:bk="urn:samples">
<book genre="novel" publicationdate="1997" bk:ISBN="1-861001-57-8">
<title>Pride And Prejudice</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>24.95</price>
</book>
<book genre="novel" publicationdate="1992" bk:ISBN="1-861002-30-1">
<title>The Handmaid's Tale</title>
<author>
<first-name>Margaret</first-name>
<last-name>Atwood</last-name>
</author>
<price>29.95</price>
</book>
<book genre="novel" publicationdate="1991" bk:ISBN="1-861001-57-6">
<title>Emma</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>19.95</price>
</book>
<book genre="novel" publicationdate="1982" bk:ISBN="1-861001-45-3">
<title>Sense and Sensibility</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>19.95</price>
</book>
</bookstore>