Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 20th, 2011, 09:21 AM
Registered User
 
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Loop through recordset to output XML

Hi everyone,

I need to generate an XML file from the 2 tables below:

dbo.Guides - ID (int), Title (varchar)

dbo.Steps - ID (int), GuideID (int), Info (varchar)

Each guide has many steps which are linked by dbo.Guides.ID and dbo.Steps.GuideID

Here is my current attempt (recordsets are [1] SELECT * FROM dbo.guides [2] SELECT * FROM dbo.steps):

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<internal_guides>
<% While (Not guides.EOF) %>
	<guide>
		<id><![CDATA[<%=(guides.Fields.Item("ID").Value)%>]]></id>
		<title><![CDATA[<%=(guides.Fields.Item("Title").Value)%>]]></title>
<% Do While (steps.Fields.Item("GuideID").Value) = (guides.Fields.Item("ID").Value) %>
		<step><![CDATA[<%=(steps.Fields.Item("Info").Value)%>]]></step>
<% steps.MoveNext()
	Loop %>
	</guide>
<% guides.MoveNext()
	Wend %>
</internal_guides>
<%
guides.Close()
	Set guides= Nothing
steps.Close()
	Set steps = Nothing
%>
It outputs the XML OK if I remove the Do While... Loop and <steps> node, but when the Do While... Loop and <steps> node are present I get 'XML Parsing Error: not well-formed'.

I'm by no means an expert ASP guru, I'm hoping one of you experts can help on this as it is pretty urgent.

Thanks for any help you can give, it is much appreciated!! :)
 
Old April 22nd, 2011, 04:43 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

I think you should add one more tag for Steps. Example:

Code:
<% While (Not guides.EOF) %>
	<guide>
		<id><![CDATA[<%=(guides.Fields.Item("ID").Value)%>]]></id>
		<title><![CDATA[<%=(guides.Fields.Item("Title").Value)%>]]></title>
<steps>
<% Do While (steps.Fields.Item("GuideID").Value) = (guides.Fields.Item("ID").Value) %>
		<step><![CDATA[<%=(steps.Fields.Item("Info").Value)%>]]></step>
<% steps.MoveNext()
</steps>
 Loop %>
	</guide>
__________________
Om Prakash Pant
Click the "Thanks" button if this post helped you.
 
Old April 25th, 2011, 11:04 AM
Authorized User
 
Join Date: Dec 2004
Posts: 69
Thanks: 0
Thanked 5 Times in 5 Posts
Send a message via Yahoo to whiterainbow
Default

As well check for the special characters in the title that breaks the formation of the XML string.
__________________
Thanks in advance.

Regards,

Senthil Kumar M.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Output loop data to a string iloveoatmeal Classic ASP Basics 2 December 22nd, 2005 08:28 PM
recordset not showing up on page loop pablohoney Classic ASP Databases 1 December 14th, 2005 06:43 PM
Querying Recordset with a Loop rabu Access VBA 10 December 14th, 2005 04:49 PM
Filter recordset in loop Freddyfred Access 1 February 15th, 2005 09:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.