VB and XML question

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

Fergus Cooney

Hi Jared,

History.xml doesn't load in IE because I don't have the schema so I
replaced <log xmlns="x-schema:ApproveSchema.xml"> with just <log>.

Then I tried your code and it works perfectly for me:

329170: Security Update (Windows 2000)com_microsoft.329170 Security Update
Windows 2000unapproved0Success
329170: Security Updatecom_microsoft.329170 Security Update Windows
XPunapproved0Success
331953: Security Update (Windows
2000)com_microsoft.331953_W2K_5918unapproved0Success
331953: Security Update (Windows
XP)com_microsoft.331953_WXP_5919unapproved0Success

You say it doesn't work. Can you be more specific?

Regards,
Fergus
 
J

Jared

I can't just replace it like that though, this specific file is created and
maintainted by the Microsoft Software Update Service. I have the schema, if
that's what's causing the problem how do I reference the item nodes using
the schema?
Thanks,
Jared

Attached is the contents of the schema file:

<Schema name="ApproveHistory" xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
<AttributeType name ="loc" required="yes" dt:type="string"/>
<AttributeType name ="time" required="yes" dt:type="dateTime"/>
<AttributeType name ="user" required="yes" dt:type="string"/>

<ElementType name="title" content="textOnly" dt:type="string"
model="closed"/>
<ElementType name="itemID" content="textOnly" dt:type="string"
model="closed"/>
<ElementType name="status" content="textOnly" dt:type="string"
model="closed"/>
<ElementType name="fileName" content="textOnly" dt:type="string"
model="closed"/>
<ElementType name="loc" content="textOnly" dt:type="string"
model="closed"/>
<ElementType name="missing" content="textOnly" dt:type="string"
model="closed"/>
<ElementType name="locList" content="eltOnly" model="closed">
<element type="loc" minOccurs ="0" maxOccurs ="*" />
</ElementType>
<ElementType name="resultCode" content="textOnly" model="closed"/>
<ElementType name="resultText" content="textOnly" dt:type="string"
model="closed"/>
<ElementType name="item" content="eltOnly" model="closed">
<element type="title" />
<element type="itemID" />
<element type="fileName" minOccurs ="0" maxOccurs ="1"/>
<element type="status" />
<element type="missing" minOccurs ="0" maxOccurs ="1"/>
<element type="locList" minOccurs ="0" maxOccurs ="*"/>
<element type="resultCode" />
<element type="resultText" />
</ElementType>
<ElementType name="itemList" content="eltOnly" model="closed">
<element type="item" minOccurs ="0" maxOccurs ="*" />
</ElementType>
<ElementType name="startType" content="textOnly" dt:type="string"
model="closed"/>
<ElementType name="approve" content="eltOnly" model="closed">
<element type="startType" />
<element type="resultCode" />
<element type="resultText" />
<element type="itemList" />
</ElementType>
<ElementType name="entry" content="eltOnly" model="closed">
<attribute type="loc" required="yes" />
<attribute type="time" required="yes" />
<attribute type="user" required="no" />
<element type="approve" />
</ElementType>
<ElementType name="log" content="eltOnly" model="closed">
<element type="entry" minOccurs ="0" maxOccurs ="*" />
</ElementType>
</Schema>
 
F

Fergus Cooney

Hi Jared,

You still haven't told me what's going wrong!!

Exceptions? Reboots? Little beeps? Nothing?

Regards,
Fergus
 
J

Jared

It return a node count of 0, it just does not get the item nodes. That is
it, no exceptions, I just don't get the data that I want. Thanks,
Jared
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top