borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB Home | News Home | Forum Home | Downloads | Register | Search | PM | Profile

Previous Topic (Passing Objects from page to page)Next Topic (DISCOVER VISUAL EXPERT!!!) New Topic Post Reply
AndreaVB OnLine : Articles and tutorials : XML.. and MSXML4 <-- medium VB, basic XML
Poster Resource
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon 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)

06-05-2004 at 12:20 AM
View Profile Send Email to User Show All Posts | Add Comment
pavane
Level: VB Lord

Registered: 26-04-2004
Posts: 179
icon Re: XML.. and MSXML4 &lt;-- medium VB, basic XML

Note for users of obolete systems:

My setup, with VB5 and Win98, is similar, but I have to use DOM version 3. The reference is to Microsoft XML3, and the objects must be declared as DomDocument30

06-07-2004 at 11:48 AM
View Profile Send Email to User Show All Posts Visit Homepage | Add Comment
AndreaVB OnLine : Articles and tutorials : XML.. and MSXML4 &lt;-- medium VB, basic XML
Previous Topic (Passing Objects from page to page)Next Topic (DISCOVER VISUAL EXPERT!!!)New Topic Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder