Wrox Programmer Forums
|
Classic ASP XML Using ASP 3 and XML. See also the XML category for more XML discussions not relating to ASP. 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 XML 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 August 22nd, 2010, 11:29 AM
Registered User
 
Join Date: Aug 2010
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Unfortunitly I get the same result :


Code:
<vnumber>84368</vnumber> 
  <license>SG84368</license> 
  <agency>J04</agency> 
  </table>
- <table>
  <vnumber>84401</vnumber> 
  <license>SG84401</license> 
  <agency>J04</agency> 
The XML page cannot be displayed 

Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later. 


--------------------------------------------------------------------------------

The following tags were not closed: NewDataSet. Error processing resource 'http://localhost/vehicle/datasetdata.asp'. 


V>  </table>
- <table>
  <vnumber>84491</vnumber> 
  <license>SG84491</license> 
  <agency>J04</agency> 
  </table>
- <table>
  <vnumber>84797</vnumber>

Let me ask a question .. the reason I am building this xml is to pass it to an AJAX grid from a library called Bindows ..


Code:
<?xml version="1.0"?>

<Application>
	<Window caption="Tree View Test6" width="500" height="400">
		<TreeView left="5" top="5" bottom="5" right="5">

			<TreeView.dataModel>
				<DataSetDataModel>
					<DataSetDataModel.dataSet>
						<XmlDataSet uri="datasetdata.asp"/>
					</DataSetDataModel.dataSet>
				</DataSetDataModel>
			</TreeView.dataModel>

		</TreeView>
	</Window>
</Application>

It is the result of the .asp code or the xml that gets passed to

<XmlDataSet uri="datasetdata.asp"/>

Is there a way instead of writing out the xml to just build a 'string' value of the xml output and have it return that 'string' from the .asp file ??

Thanks
Rick Lipkin
[email protected]
 
Old August 24th, 2010, 03:33 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

AJAX *depends* on getting an HTTP RESPONSE (in response to the HTTP REQUEST that it issues). So, ultimately, you have to send the XML by way of HTTP response.

And there's truly no difference between create an HTTP response "on the fly" versus building one up as a big long string and then using Response.Write, so far as AJAX is concerned. It's all an HTTP RESPONSE. But there's a huge difference to ASP and VBScript. Two differences: (1) Building up a big long string using VBScript can get PAINFULLY slow. (2) If you try to build too long a string, you end up overflowing the IIS response buffer AND/OR VBScript's internal string buffers.

So, no, I would definitely not go that route.

*************

There *IS* another possible route. It's a bit ugly,but at this point maybe you are ready to try ugly???

Instead of writing the XML directly back to the HTTP Response, write it to a *FILE*. Then have your client-side code *first* hit your ASP URL and *then* actually go get the XML (could be done using a synchrononlus request) via a second call, this time asking for the file.

Big advantage: You can actually look at the file and maybe see exactly what is going wrong (if anything!). Big disadvantages: (1) You will have to rewrite your code (yet again) to write to a file instead of using Response.Write. (2) Your client side code will have to make the dual requests.
 
Old August 24th, 2010, 03:52 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

There's another thing you should look into: SQL Server *CAN* be asked to produce XML output, directly. So maybe you could do a SQL query "FOR XML" and *maybe* that won't have the same problems???

http://msdn.microsoft.com/en-us/library/ms173812.aspx

You could then convert all the XML thus generated into HTTP Response by simply using:
Code:
Response.Write RS.GetString()
Ugh...unless that exceeded the Response.Write buffer size!

Well, workarounds for that, too.
 
Old August 24th, 2010, 05:06 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
(2) Your client side code will have to make the dual requests.
Or you could use Response.Redirect("PhysicalFile.xml") from the ASP page generating the file? Then there's no need to modify client code...

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 24th, 2010, 05:12 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Ahhh...I wasn't sure that AJAX would follow a redirect, but I suppose it makes sense it would, since presumably the browser is handling the HTTP connection. I like it!
 
Old August 24th, 2010, 05:17 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I am not 100% sure, but I think it does. Worth giving it a try if the OP goes the "ugly" route of writing files.... ;-)

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 24th, 2010, 05:59 PM
Registered User
 
Join Date: Aug 2010
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Does this work in .ASPX ??

Or you could use Response.Redirect("PhysicalFile.xml") from the ASP page generating the file? Then there's no need to modify client code

I am toying with Web Service Endpoints and soap requests to basically request the HTTP .. here is some code I found at this link :

http://www.developer.com/db/article....erver-2005.htm

here is the code .. it works .. but I have no clue how to apply it to the above XML code

CREATE PROC dbo.SalesStoreProc
AS
SELECT
CustomerID,
Name
FROM
Sales.Store

The next step is to create the HTTP endpoint. Running this SQL statement is what makes the data from the stored procedure available to SOAP clients:


CREATE ENDPOINT GetStores
STATE = STARTED
AS HTTP
(
PATH = '/Store',
AUTHENTICATION = (INTEGRATED),
PORTS = (CLEAR),
SITE = 'localhost'
)
FOR SOAP
(
WEBMETHOD 'StoreList'
(NAME='AdventureWorks.dbo.SalesStoreProc'),
BATCHES = DISABLED,
WSDL = DEFAULT,
DATABASE = 'AdventureWorks',
NAMESPACE = 'http://AdventureWorks/Store'
)
GO

I am using the above but it seems to output the schima wrong .. if anyone has any ideas on creating web services on SQL Server 2005\2008 ?? .. ultimately that is the reason I started down the .asp path in the first place ..but all the AJAX people I need to think along the lines of HTTP requests to get my data to bind to my web application..

Totally lost here .. sorry,

Rick Lipkin
[email protected]
 
Old August 24th, 2010, 09:13 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Maybe Imar can help on this. Not something I've ever done.
 
Old August 25th, 2010, 08:19 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Neither have I.... ;-(

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old September 1st, 2010, 09:39 PM
Registered User
 
Join Date: Sep 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Arrow A different approch

Quote:
Originally Posted by lipkinrm View Post
I am trying to write a classic asp routine to connect to a sqlexpress 2008 ( local server ) and extract an xml file from a very simple table .. the code you see has the schema part remarked out and I will deal with that later .. here is the code :

Code:
<%

response.ContentType = "text/xml"
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB; Data Source = RICKLIPKIN-PC\SQLEXPRESS; Initial Catalog = VEHICLE; User Id = vehicleuser; Password=lipkinrm"

sql="select vnumber,license,agency from vehicles order by vnumber"
set rs=Conn.Execute(sql)

response.write("<?xml version='1.0' encoding='ISO-8859-1'?>")
'response.write("<?xml version='1.0' encoding='UTF-8'?>")

                                        
response.write("<NewDataSet>")
'response.write("<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">")
'    response.write("<xs:element name="NewDataSet" msdata:IsDataSet="true">" )
'      response.write("<xs:complexType>" )
'        response.write("<xs:choice maxOccurs="unbounded">" )
'          response.write("<xs:element name="Table">" )
'            response.write("<xs:complexType>" )
'              response.write("<xs:sequence>" )
'                response.write("<xs:element name="vnumber" type="xs:int" minOccurs="0" />" )
'                response.write("<xs:element name="license" type="xs:string" minOccurs="0" />" )
'                response.write("<xs:element name="type" type="xs:string" minOccurs="0" />" )
'              response.write("</xs:sequence>")
'            response.write("</xs:complexType>")
'          response.write("</xs:element>")
'        response.write("</xs:choice>")
'      response.write("</xs:complexType>")
'    response.write("</xs:element>")
'response.write("</xs:schema>")

While NOT rs.EOF
        response.write("<table>")
 
        sMyString = rs("vnumber")
        sMyString = Replace(sMyString, "/", " " )
        response.write("<vnumber>" & sMyString & "</vnumber>")

        sMyString = rs("license")
        sMyString = Replace(sMyString, "/", " " )
        response.write("<license>" & sMyString & "</license>")

        sMyString = rs("agency")
        sMyString = Replace(sMyString, "/", " " )
        sMyString = Replace(sMyString, "-", " " ) 

        response.write("<agency>" & sMyString & "</agency>")        

        response.write("</table>")

        rs.MoveNext()

Wend 


rs.Close()
conn.Close()

response write("</NewDataSet>")

%>

and about 95% of the way through the loop I get this error :

<vnumber>84401</vnumber>
<license>SG84401</license>
<agency>J04</agency>
</vehicles>
- <vehicles>
<vnumber>84491</vnumber>
<license>SG84491</license>
<agency>J04</agency>
</vehicles>
- <
The XML page cannot be displayed

Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
The following tags were not closed: NewDataSet. Error processing resource 'http://localhost/vehicle/datasetdata.asp'.


SPAN>vehicles>
<vnumber>84797</vnumber>

Any Ideas what is going on here .. it does not appear to be a data problem but the error occurs at the same place each time ..

Any advice would be helpful!!

Rick Lipkin
[email protected]

Lipkin, I would try a different approach. Assuming that you are able to install 3rd party software on the server. I would do the following.

1. Download and Install Chilkat XML ActiveX (Free)

2. Look at the on-line examples

3. Update the look to look something like this

While NOT rs.EOF
oXML.NewChild2 "table", ""

oXML.NewChild2 "vnumber", Replace(rs("vnumber"), "/", " ")
oXML.NewChild2 "license", Replace(rs("license"), "/", " ")


sMyString = rs("agency")
sMyString = Replace(sMyString, "/", " " )
sMyString = Replace(sMyString, "-", " " )
oXML.NewChild2 "agency", sMyString

oXML.GetParent2
rs.MoveNext()

Wend


3. Send the XML to the browser or calling AJax page

With Response
.Clear
.ContentType = "text/xml"
.Write oXML.GetXml

End With





Similar Threads
Thread Thread Starter Forum Replies Last Post
classic ASP to ASP.NET 2.o XML coding rupen XML 10 May 18th, 2010 03:09 AM
classic ASP to ASP.NET 2.o XML coding rupen ASP.NET 2.0 Basics 0 May 14th, 2010 07:25 AM
Relational SQL Data to XML - Vet SQL/ASP - New XML JimiTheJett XML 1 December 4th, 2008 06:06 PM
xml invalid top level from ASP write XML(solution) g000we XML 0 August 9th, 2006 03:56 AM
XML, XML Schema, JavaScript, ASP cyberjames2003 XML 0 June 4th, 2003 04:49 AM





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