stickleprojects Level: Moderator

 Registered: 09-09-2002 Posts: 891
|
XML.. and MSXML4 <-- medium VB, basic XML
OK.. quickie example:
XML is a tagged file format where each piece of data is surrounded by it's description. An example of an xml fragment (piece) is:
<PERSON>
<NAME>Kieron</NAME>
<AGE>28</AGE>
<ADDRESS>
<STREET>wolacombe st</STREET>
<COUNTRY>UK</COUNTRY>
</ADDRESS>
</PERSON>
Note how each item (element) begins with a <TAG> and ends with an </TAG>
Also, for an XML document to be valid (ie. OK), there must be only one root element in the document.. so to get a few people together you could use the following...
<CLASS>
<PERSON>
<NAME>Kieron</NAME>
</PERSON>
<PERSON>
<NAME>Fred</NAME>
</PERSON>
</CLASS>
You could also add the AGE and ADDRESS information, etc.
Ok,
So save the XML fragment into a file called "person.xml".
The microsoft parser (language to load an XML document into memory) is called a DOM (Document Object Model)
In VB.
Create a project and add a reference to Microsoft XML 4.
Add the code:
private sub form_load
dim objDOM as DomDocument40
set objDOM = new DomDocument40
if not objDom.load("person.xml") then
msgbox "Did not load person.xml because " & objDom.ParseError.Reason
exit sub
end if
end sub
The following code will output the name of the person:
dim ndPerson as Ixmldomnode
set ndPerson = objDOM.SelectSingleNode("/PERSON/NAME")
msgbox ndPerson.text
set ndPerson = nothing
If you had a "class of people" document - as described above - you could use
..
set ndPerson = objDOM.SelectSingleNode("/CLASS/PERSON/NAME")
..
I hope this helps,
Kieron
____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)
|