Visual Basic 6.0 and XML PDF Print E-mail
User Rating: / 0
PoorBest 
Tuesday, 15 July 2008
I. Some concepts
A. The XML, what is it?

 It is a language that can describe a class of objects "documents xml". Within these documents, XML imposes a structure to be read data in a simple text format. XML uses the well-known principle of tags but these are specific to the creator of the document and not standardized like HTML. It is obviously imperative to choose its markup for a proper understanding of the structure of the document. An example is far more speaking:
 <? xml version = "1.0" encoding = "ISO-8859-1"?>
 <developpez>
 <member fonction="Responsable Visual Basic">
 <name> Cécile Muno </ name>
 <nick> khany </ pseudo>
 <activite>
 <date-inscription> 20/10/2002 </ date-registration>
 <nbmsg> 1721 </ nbmsg>
 <nbtutoriel> 4 </ nbtutoriel>
 </ activity>
 </ member>
 <membre>
 <nom/>
 <nick> jpdar </ pseudo>
 <activite>
 <date-inscription> 29/12/2005 </ date-registration>
 <nbmsg> 14 </ nbmsg>
 <nbtutoriel> 0 </ nbtutoriel>
 </ activity>
 </ member>
 <member fonction="admin">
 <name> Cédric Chatelain </ name>
 <nick> cchatelain </ pseudo>
 <activite>
 <date-inscription> 26/05/2002 </ date-registration>
 <nbmsg> 2840 </ nbmsg>
 <nbtutoriel> 10 </ nbtutoriel>
 </ activity>
 </ member>
 </ expand>
 
 B. A few vocabulary
 For those who have little or no had the opportunity to rub the XML format, here's a very quick overview of the vocabulary related to this standard. For more information, visit the forum XML.
 
 An XML document is recognizable by:
 * The elements of marking a component consists of an opening tag, the associated closing tag and all that lies between these tags.
 * An opening tag may also contain one or several "attributes"
 * Nodes: essence of XML document, they model all elements and the document itself is modeled on the node "/" called "root of the XML document"
 
 By resuming our previous example, we can therefore say:
 <!--- Tags ouvrantes/fermantes--->
 <developpez> </ expand>
 <!--- Attributes: Depending on the tag member --->
 <member fonction="Responsable Visual Basic">
 </ member>
 <!--- Elements --->
 <membre>
 <nom/>
 <nick> ...</ pseudo>
 <nbmsg> ...</ nbmsg>
 </ member>
 And to give you an idea of the arrangement of knots, here is a part of the representation of the XML tree associated with this example:
 

C. Some "good" reasons for using XML
There are a lot and its use exclusively depends on the type of application you need to write, but be aware that this standard may be invariably used for the following reasons:
* Ease of reading an XML document by anyone
* The increasing number of applications using this standard and optimize
* Simplicity of use on the Intranet / Extranet
* Rapid creation of a structure XML
* Ease of operation through the code of this type of document
* Uselessness of training to encode data in such a format
* Import and export data to and from multiple applications
* ...

II. Operates XML
A. References

As with any non-component appears at the base in Visual Basic 6, it is obviously necessary to check the good references before using the XML standard. Over time, this standard has continued its evolution in operating systems, there is several references. In this small project, I chose Microsoft XML 3.0 because it is installed automatically with Internet Explorer 6 and you do so no problem to run this program.

 

 

Microsoft XML v2.6


B. The principle of evolution in an XML document
As you have seen on the image of the tree of our XML document, the principle of development is based on levels of tags. Many see the logic of this cascade of knots is essential to develop the operating code. Indeed, the principle is always the same regardless of manipulation to be carried out on the document: it is necessary to progress logically in knots, level by level. You can actually not directly reach a node level 3 without having appears nodes higher level beforehand.

In the example document that we will exploit, here is a diagram to explain more simply levels of nodes:
Levels knots
Purists of the XML standard n'aimeront maybe not this kind of "nivellage" but it is much easier to find programming in well with a view to the number of nodes to be set for progress in the document. Aided by the XML tree, thereby making it easy to place your "definitions".
For example:
Sunday oDvpDOMDocument As MSXML2.IXMLDOMDocument
Sunday oNoeudMembre As MSXML2.IXMLDOMElement element member
Sunday oNoeudEnfantMembre As MSXML2.IXMLDOMElement element son of oNoeudMembre
Sunday oNoeudEnfantMembreActivite As MSXML2.IXMLDOMElement element son of oNoeudEnfantMembre

This is obviously an example because sometimes there is no need to declare all nodes children, you can go from one node to the same level to another node on the same level without declaring nodes children.

C. The main statements related to XML

This list is reduced to its simplest expression for both existing elements for the methods and associated properties.

1. MSXML2.DOMDocument
Used to declare a variable as referring to the XML document used.
This variable, recognized as an XML document, has methods that can exploit the document.
For example, if I want to add something to my document, I can schedule it as follows:
Set oNoeudMembre = oDvpDOMDocument.createElement ( "member")
specifying thanks to Set how I add an element node.

2. MSXML2.IXMLDOMElement
Concerns obviously elements of XML document and therefore the "levels" that I can go. See again the example of "nivellage."
These elements have also methods for carrying out various actions. The simplest to understand and grasp seem to be:
* GetAttribute: You can read the attribute of the element
* GetElementsByTagName: You can find the value of an element by the name of the tag
* HasChildNodes: Allows whether knots children exist and if so, what are they.

3. MSXML2.IXMLDOMNode
As the name suggests, we work here at the knots of our XML document which have also methods such as:
* HasChildNodes: Allows whether this node has specific nodes children
* RemoveChild: You can remove a child node
* ReplaceChild: You can replace a child node by another value
* SelectSingleNode: You can select a specific node (with the tag name)

4. MSXML2.IXMLDOMNodeList
The list of nodes, as you probably guessed, can be searched fairly rapidly in knots children.
A small example to illustrate this fact:
Sunday oListeNoeuds As MSXML2.IXMLDOMNodeList
Sunday oNoeud As MSXML2.IXMLDOMNode
For Each oNoeud In oListeNoeuds
......
Next
Obviously, there are also properties as in the example above where the value of a node is defined by the property "Text".

D. Conclusion
This short overview is far too fast for you to delve into all possible methods and properties of the XML object.
To get acquainted with their use, I suggest a few small codes simple, just to understand the logic of operating an XML document.
warning These codes are available by downloading the application Visual Basic 6.0 associated with this tutorial.

III. Some simple codes
A. Open XML

It is fair to draw attention to the fact that there are two ways to load an XML document: synchronous or asynchronous.
By default, the file is loaded asynchronously. We must specify:
oDvpDOMDocument.async = False
to load the entire document in memory. This will be the case in the examples associated with the tutorial because the file is local and very small.
The document will be responsible for each action chosen in the example in order not to compel an execution order specific examples provided.
You can choose any action on the application as an example to see the code of openness and loading an XML document.

B. Search for a given
The principle of the research is to go nodes from the root, is looking for a specific tag, is seeking an attribute.
We must therefore make sure to define the "elements", "nodes", "nodelist" which may require. Obviously, in the example is quite simple since we know the document structure and name tags.
The programming is more difficult if one must start with an XML document which does not know the structure. This is not the goal in this introduction.
The example joint research a pseudo precise.

C. Add a given
The addition concerns are always pointing to the root of the XML document that we will create a new element.
Once you understand this, find the code is relatively simple knowing that the procedure is the same for each level of creating a tag.
The warning is important to understand that to create a new element, it takes 2 instructions. The method "createElement" does not create the tag, it is really implemented until the implementation of the method "appendChild."

D. Upgrading a given

The updating of data is still based on the same principle that research with the sole difference that it modifies the data contained in the tag targeted. It then proceeds to amending the Text property, which is a fairly easy thing to achieve.

E. Creating an XML document

Very similar to adding data unless it is necessary to create the document in placing the header with this kind of document and the ad hoc extension.

F. Error Handling
A simple example of error handling via "parse Error".

IV. Interactive Tutorial

I suggest, based on the example associated with this tutorial to make it interactive.
The exploitation of XML documents is a very wide area, I thought it best to help users would be able to change this tutorial with your own achievements.
To do this, we must clearly establish some rules governing the organization and how you can expand these codes rather simplistic.
It is necessary to lay the groundwork for the organization so that the system is efficient and attractive to all viewpoints.
If you want your proposal is submitted, I therefore urge you to follow these requirements:

A. How to organize your proposals?
In a few points, here's how:
* Based on the example attached to this tutorial by adding a sheet with your name / nickname.
* Based on the XML document used. You can change according to your needs, but in this case, make a copy and call it "dvp-xxxx.xml" or "xxx" is your name / pseudo
* Launching the performance of your leaf from the leaf Selection having placed a new button with an explicit
* Comment clearly your code without user abbreviations.

B. How to write your explanation?

It is obvious that the codes can not only learn about what you wanted to achieve. A substantial explanation is therefore necessary accompaniment.
Please observe these guidelines in your explanations:
* Additional details on what operating system you are working and any other information which could affect the implementation of the code.
* Please describe exactly what items are needed and possibly take the trouble to make a screenshot to show the (es) reference (s) checked.
* At the beginning of your explanations, made a succinct summary of the purpose of your code.
* Be clear and precise in the narrative, avoid abbreviations and style SMS.
* Enter the text in a word processor to use common even in the notepad, this is quite sufficient. The layout is not necessary (unless you want chapitrer the text), it will in any way appropriate for the current format of the tutorial.

C. How to send me your contribution?
To integrate your proposal in this tutorial, it is necessary that I receive, in the form of files "ZIP":
* The example program initial completed by your (your) sheet (s) and zipped into a file named "xml.zip".
* Your explanations zipped file in a file named "expl-xxx.zip" where "xxx" is your name / nickname.
* Possibly a zipped file containing your images under the name "images-xxx.zip" where xxx is your name / nickname.
* Tell Me by MP for me to point out your participation. Send me the zip on my writing mail or give me a link where to download them. (You can combine different *. zip in one zip with your name / nickname).
* Any communication regarding your proposal before or after completion will be made exclusively by MP.

D. Integration tutorial
I charge of integrating your comments and the amended programme in this tutorial referencant, of course, that you are the sole author. The published sources are always free to right, but the text is protected like all the tutorials published on develop.

I also specifies that the integration of your code is subject to approval by the Visual Basic team about its need, how to code, the relevance of comments and explanations as well as ease of implementation. It is clear that we will keep you abreast of any comments to change your proposal positively and achieve its integration.

Some important points warning
* Your code must respond to a general use fairly common and comprehensive as the proposed solution.
* Will not be accepted that the proper codes and indentés commented.
* Will not be accepted as codes accompanied by a roster of clear and complete.
* The code must be tested and running a standard installation of Visual Basic 6.0.
* The acceptance or refusal of a code is the responsibility of the whole team Visual Basic. It will not be taken into account any enquiry, claim, question or any correspondence would not be drafted in accordance with the rules of developpez.com (sms, spelling, politeness, ...).
A codes and your good work!

V. Downloads


Course in PDF format (http mirror)
  Application Visual Basic 6 (mirror http)

VI. Links
XML: Definition
XML: Introductory course
Microsoft XML: Information and Download

VI. Acknowledgments

A whole team Visual Basic and more particularly to Argyronet for his wise counsel and the reading of the course.
I already want to thank all participants for the future development of this tutorial.

 

 
< Prev   Next >
School Joomla Templates and Joomla Tutorials