Reasons to Use XML Data Binding
| |
- Reduces Development Time
- Increased reliability (spot problems at compile time not runtime)
- Creates more readable code
- Fastest root between code and XML
|
|
Reasons To Use Liquid XML Data Binding Code Generator
| |
|
- Generates simple intuitive code
- Supports XSD, XDR & DTD's
- Ideal for legacy integration projects
|
|
|
Xml Data Binding
XML Data Binding allows you to treat your XML documents as objects within your application. This makes dealing with XML data from a programming language a simple matter of manipulating these strongly typed objects.
Liquid XML Data Binding Code Generator takes an XML Schema and uses it to generate a class library. These classes map directly to to data contained in your XML Schema, so if your schema has an Person entity and that has a date of birth attribute, then a class called Person will be generated, which will have a property called DateOfBirth. |
|
No other product supports Visual Basic
Its sad to say to companies just aren't developing Visual basic tools anymore. Liquid is now the only, company with an XML Data Binding solution for Visual Basic 6.
Migration path to VB.Net
Because we support VB.Net and C# as well as VB6, any code you write for VB6 is easily ported to .Net, as the libraries interfaces are all but identical to the VB ones.
|
|
Tools Included with Liquid XML Studio
Liquid XML Data Binding Code Generator is included in the Developer Edition of Liquid XML Studio, which includes many other XML tools including
XSD Editor, XML Editor, XML Differencing tool, XPath Query viewer, Web Service Call Composer and more... see Liquid XML Studio.
|
 |
A Simple Example
The following example we will use the Person.xsd, shown below to demonstrate how to read and write an XML document based on this schema.
XML Schema - Bookstore.xsd - Click to View
Serializing the XML (Objects to XML) - Code to create an XML document using XML Data Binding Objects - Click to View
Using XML Data Binding |
Using the standard DOM approach |
1 Dim p As New Person
2 Dim c As Car
3
4 ' Load the XML
5 p.FromXmlFile "SampleFile.xml"
6
7 Debug.Print p.Name_ & " was born " & _
8 p.DateOfBirth.ToString & ", and lives at " & _
9 p.Address.HouseNo & ", " & _
10 p.Address.PostCode
11
12 Debug.Print "Cars Owned (" & p.Cars.Count & ")"
13 For Each c In p.Cars
14 Debug.Print " " & c.Make & ", " & c.Model
15 Next
|
1 Dim xmlDoc As New MSXML2.DOMDocument
2
3 xmlDoc.Load ("SampleFile.xml")
4
5 Dim xmlElmPerson As MSXML2.IXMLDOMElement
6 Set xmlElmPerson = GetFirstElement(xmlDoc)
7 If xmlElmPerson Is Nothing Then
8 Err.Raise -1, "Test", "Must start with Person"
9 ElseIf xmlElmPerson.nodeName <> "Person" Then
10 Err.Raise -1, "Test", "Unexpected element"
11 End If
12
13 Dim xmlElmName As MSXML2.IXMLDOMElement
14 Set xmlElmName = GetFirstElement(xmlElmPerson)
15 If xmlElmName Is Nothing Then
16 Err.Raise -1, "Test", "Missing Person->Name"
17 ElseIf xmlElmName.nodeName <> "Name" Then
18 Err.Raise -1, "Test", "Unexpected element"
19 End If
20
21 Dim xmlElmDOB As MSXML2.IXMLDOMElement
22 Set xmlElmDOB = GetNextElement(xmlElmName)
23 If xmlElmDOB Is Nothing Then
24 Err.Raise -1, "Test", "Missing Person->DateOfBirth"
25 ElseIf xmlElmDOB.nodeName <> "DateOfBirth" Then
26 Err.Raise -1, "Test", "Unexpected element"
27 End If
28
29 Dim xmlElmAddress As MSXML2.IXMLDOMElement
30 Set xmlElmAddress = GetNextElement(xmlElmDOB)
31 If xmlElmAddress Is Nothing Then
32 Err.Raise -1, "Test", "Missing Person->Address"
33 ElseIf xmlElmAddress.nodeName <> "Address" Then
34 Err.Raise -1, "Test", "Unexpected element"
35 End If
36
37 Dim xmlElmHouseNo As MSXML2.IXMLDOMElement
38 Set xmlElmHouseNo = GetFirstElement(xmlElmAddress)
39 If xmlElmHouseNo Is Nothing Then
40 Err.Raise -1, "Test", "Missing Person->Address->HouseNo"
41 ElseIf xmlElmHouseNo.nodeName <> "HouseNo" Then
42 Err.Raise -1, "Test", "Unexpected element"
43 End If
44
45 Dim xmlElmPostCode As MSXML2.IXMLDOMElement
46 Set xmlElmPostCode = GetNextElement(xmlElmHouseNo)
47 If xmlElmPostCode Is Nothing Then
48 Err.Raise -1, "Test", "Missing Person->Address->PostCode"
49 ElseIf xmlElmPostCode.nodeName <> "PostCode" Then
50 Err.Raise -1, "Test", "Unexpected element"
51 End If
52
53 If (GetNextElement(xmlElmPostCode) Is Nothing) = False Then
54 Err.Raise -1, "Test", "Unexpected element"
55 End If
56
57 Debug.Print xmlElmName.Text & " was born " & _
58 xmlElmDOB.Text & ", and lives at " & _
59 xmlElmHouseNo.Text & ", " & _
60 xmlElmPostCode.Text
61
62 Dim xmlElmCar As MSXML2.IXMLDOMElement
63 Set xmlElmCar = GetNextElement(xmlElmAddress)
64 While (xmlElmCar Is Nothing) = False
65 If xmlElmCar.nodeName <> "Car" Then
66 Err.Raise -1, "Test", "Unexpected element"
67 End If
68
69 Dim xmlElmMake As MSXML2.IXMLDOMElement
70 Set xmlElmMake = GetFirstElement(xmlElmCar)
71 If xmlElmMake Is Nothing Then
72 Err.Raise -1, "Test", "Missing Person->Car->Make"
73 ElseIf xmlElmMake.nodeName <> "Make" Then
74 Err.Raise -1, "Test", "Unexpected element"
75 End If
76
77 Dim xmlElmModel As MSXML2.IXMLDOMElement
78 Set xmlElmModel = GetNextElement(xmlElmMake)
79 If xmlElmModel Is Nothing Then
80 Err.Raise -1, "Test", "Missing Person->Car->Model"
81 ElseIf xmlElmModel.nodeName <> "Model" Then
82 Err.Raise -1, "Test", "Unexpected element"
83 End If
84
85 If (GetNextElement(xmlElmModel) Is Nothing) = False Then
86 Err.Raise -1, "Test", "Unexpected Element"
87 End If
88
89 Debug.Print " " & _
90 xmlElmMake.Text & ", " & _
91 xmlElmModel.Text
92
93 Set xmlElmCar = GetNextElement(xmlElmCar)
94 Wend
1 Private Function GetFirstElement _
2 (ByVal xmlParent As IXMLDOMNode) As IXMLDOMElement
3 If xmlParent Is Nothing Then
4 Set GetFirstElement = Nothing
5 ElseIf xmlParent.firstChild Is Nothing Then
6 Set GetFirstElement = Nothing
7 ElseIf TypeOf xmlParent.firstChild Is IXMLDOMElement Then
8 Set GetFirstElement = xmlParent.firstChild
9 Else
10 Set GetFirstElement = _
11 GetNextElement(xmlParent.firstChild)
12 End If
13 End Function
14
15 Private Function GetNextElement _
16 (ByVal xmlNode As IXMLDOMNode) As IXMLDOMElement
17 While (xmlNode Is Nothing) = False
18 Set xmlNode = xmlNode.nextSibling
19 If (xmlNode Is Nothing) = False Then
20 If TypeOf xmlNode Is IXMLDOMElement Then
21 Set GetNextElement = xmlNode
22 Exit Function
23 End If
24 End If
25 Wend
26 End Function
|
The XML Data Binding code is much easier to read, more concise and will allow errors to be detected at compile time should the data model change.
The DOM code is verbose, difficult to read, and should the data model change, the errors will only be picked up in testing. |
Conclusion
XML Data Binding makes it significantly easier to deal with XML documents from within your code, resulting in less code, which is simpler to read and maintain.
As the generated class library is strongly typed, it forms a kind of template for the developer, ensuring that the data created conforms the underlying XML Schema.
The maintenance phase of a project also befits as XML Data Binding allows any errors introduced because of changes in the data model to be caught early at compile time, unlike weekly typed DOM trees, which will give no indication of a problem until runtime. These kinds of changes can be a major cause of bugs which can only be caught in testing. Being able to identify these at compile time can save huge amounts of time and effort.
|