Reading and Transforming XML Documents using Visual Basic 2005 (Page 1 of 6 )
This article mainly focuses on reading XML documents in several ways using Visual Basic.NET 2005. Topics discussed include the XMLReader and XSLT, among others.
A
downloadable zip file is available for this article.
This article mainly focuses on reading XML documents in several ways using Visual Basic.NET 2005.
If you are new to designing XML Schemas, I suggest you to refer my following articles:
http://www.devarticles.com/c/a/XML/Designing-Your-own-XML-Schema-Learn-the-
Essentials/
http://www.devarticles.com/c/a/XML/Designing-Your-own-XML-Schema-
Constraining-with-Restrictions/
http://www.devarticles.com/c/a/XML/Designing-Your-own-XML-Schema-
Restrictions-and-User-Defined-Types/
http://www.devarticles.com/c/a/XML/Designing-Your-Own-XML-Schema-Indicators/
http://www.devarticles.com/c/a/XML/Introduction-to-Relations-in-XML-Schema/
http://www.devarticles.com/c/a/XML/OneOne-OneMany-and-ManyMany-Relations-
in-XML-Schema/
The entire source code for this article is available in the form of a downloadable zip file. The solution was developed using Microsoft Visual Studio 2005 Professional Edition on Microsoft Windows Server 2003 Enterprise Edition together. I didn’t really test the solution with any other/previous editions. If you have any problems in executing the solution, please post in the discussion area.
XML Schema and XML document
An XML document is simply a text file with some hierarchical and structural user-defined tags (like HTML tags) containing user-provided data. The syntax, grammar, rules, structure, hierarchy, constraints etc. of a particular XML document is defined using XML Schema (which is also an XML document, but with the XSD extension).
To work with this article, I worked with the following XML document (Employee.xml):
<?xml version="1.0" encoding="utf-8"?>
<Employees xmlns="http://tempuri.org/Employee.xsd">
<Employee>
<Empno>1001</Empno>
<Ename>Jagadish</Ename>
<Sal>3400</Sal>
<Deptno>20</Deptno>
</Employee>
<Employee>
<Empno>1002</Empno>
<Ename>Chatarji</Ename>
<Sal>4500</Sal>
<Deptno>10</Deptno>
</Employee>
<Employee>
<Empno>1003</Empno>
<Ename>Winner</Ename>
<Sal>3700</Sal>
<Deptno>10</Deptno>
</Employee>
<Employee>
<Empno>1004</Empno>
<Ename>Dhanam</Ename>
<Sal>4300</Sal>
<Deptno>20</Deptno>
</Employee>
</Employees>
The XML Schema for the above XML document is defined as follows:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Employee" targetNamespace=
"http://tempuri.org/Employee.xsd" elementFormDefault=
"qualified" xmlns="http://tempuri.org/Employee.xsd"
xmlns:mstns="http://tempuri.org/Employee.xsd" xmlns:xs=
"http://www.w3.org/2001/XMLSchema">
<xs:element name="Employees">
<xs:complexType>
<xs:sequence>
<xs:element name="Employee" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Empno" type="xs:string"/>
<xs:element name="Ename" type="xs:string"/>
<xs:element name="Sal" type="xs:int"/>
<xs:element name="Deptno" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Next: Reading the tags in an XML document using XMLReader >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee