Published: Saturday, June 10, 2000
Converting Hierarchical Recordsets Into XML, Part 4
By Richard Chisholm
Read Part 1
Read Part 2
Read Part 3
That's it really. The function runs again, and if any more child recordsets are found, will be called again,
etc. If the function runs through the available recordset and has added all the data without finding any
children, it destroys all the objects and falls back to the "parent" function. As you can see, not a whole
lot of code is involved, and much of it is duplicated on either side of the IF...THEN...ELSE statement.
Now, assuming all the data from the recordsets have been added to the XML document and the first Create_XML
function is done, we need to pass it back to the ASP page. Back in the Convert() function, after
the initial call to Create_XMLNode, is the command to pass back the XML data. This is
accomplished by doing this:
'Pass the xml back to the asp page
Convert = XMLDoc.xml
|
If you look at the declaration of the function, you will notice its type is set to Variant, the
data type of ASP VBScript. But more important is the use of the .xml property type. This is a
proprietary extension by Microsoft to the XML Object Model that returns a string representation of the XML
document. This allows the component to pass back a string rather than a DOMDocument object, and since no more
work needs to be done on the XML document, this is all the ASP page needs. It simply outputs the returned string.
Here is the relevant code to the ASP page (the complete file is included below with all the other source material):
strXMLCode = objCvtXML.Convert
If objCvtXML.ErrorExists <> "True" and Err.number = 0 then ' Simple Error Checking
Response.ContentType = "text/xml"
Response.Write(strXMLCode)
Else
Error trapping/statement
End If
|
Conclusion
To see the results of this component, check out this XML file to view the output in
IE5. As you can see, we still have some work to do. Although it is nested, the data structure is linear and
not particularly well formatted to the way you would want to use it. For example, the data from each recordset
"row" should ideally be separated as its own node. However, in the next article I will show you how to tweak
the code to produce the desired structure. Another problem that will need to be covered is handling special
charactersl like ? and <. For now, if you are so inclined, I suggest you play
with the SQL statements and the code to see what you get. If you come across anything interesting, feel free
to let me know. I'll gladly take accept any advice or requests for what you want to see in the next few
articles, but I don't gaurantee I will respond. I will try, but I can't access the Internet at home
right now (waiting for DSL to be installed).
Now that you've completed this article, be sure to read part two of the series,
Customizing the COMponent to Create an XML Structure!
Happy Programming!
Attachments:
Download the VB Project files in ZIP format
Related Articles:
Customizing the COMponent to Create an XML Structure
XML Article Listing
Data Shaping
Advanced Data Shaping Techniques
Richard
Chisholm is the Webmaster of a large California
law firm, as well as an independent developer. He
runs a website dedicated to blues music in
his spare time.