|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThe XML Parser classes are used to simplify the process of loading and accessing a regular XML file. Some key features:
The full documentation is included in the zip file. It's documentation.chm. BackgroundSome knowledge of how XML files are built is required if you are the one writing the XML files. If you are just reading someone else's file, just know that a XML file is much like a Windows Explorer Tree, in the aspect that each node can have subnodes and value. Using the codeThe document1.xml file i'm using as an example: <?xml version="1.0" encoding="utf-8" ?>
<root>
<parent type="Father">John</parent>
<parent type="Mother">Mary</parent>
<child id="FirstSon">
<name>Joseph</name>r> </child>
<child id="SecondSon">
<name>Christian</name>r> </child>
</root>
Using the code to load a "document1.xml" file: Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Dim xmlRoot As New SNANET.XMLParser.XMLRoot(
Server.MapPath("xmlFile1.xml"))
If xmlRoot.isLoaded Then
response.write ("File succesfully loaded.")
End If
End Sub
Using the code to access the child node number 0 of the root node: Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Dim xmlRoot As New SNANET.XMLParser.XMLRoot(
Server.MapPath("xmlFile1.xml"))
If xmlRoot.isLoaded Then
response.write (xmlRoot.children(0).name & "="
& xmlRoot.children(0).value)
End If
End Sub
Using the code to access the child node number 0 of the root node and print it's attributes: Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Dim xmlRoot As New SNANET.XMLParser.XMLRoot(
Server.MapPath("xmlFile1.xml"))
If xmlRoot.isLoaded Then
For Each att as SNANET.XMLParser.XMLAttribute In xmlRoot.Attributes
Response.Write (att.name & "=" & att.value)
Next
End If
End Sub
Using the code to access the child nodes that has the name "Child": Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Dim xmlRoot As New SNANET.XMLParser.XMLRoot(
Server.MapPath("xmlFile1.xml"))
If xmlRoot.isLoaded Then
For Each item As SNANET.XMLParser.XMLNode In xmlRoot.GetNodesByName("child")
Response.Write(item.Name & "=" & item.value)
Next
End If
End Sub
Using the code to access the child nodes that has the attribute "type" and that attribute has the value of "Father": Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Dim xmlRoot As New SNANET.XMLParser.XMLRoot(
Server.MapPath("xmlFile1.xml"))
If xmlRoot.isLoaded Then
For Each item As SNANET.XMLParser.XMLNode
In xmlRoot.GetNodesByType("type","father")
Response.Write(item.Name & "=" & item.value)
Next
End If
End Sub
To-Do List (help is most welcome :))
History
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||