load xml with asp

Results 1 to 2 of 2

Thread: load xml with asp

  1. #1
    Cefe Guest

    Default load xml with asp

    I am trying to laod an xml document with asp using the load method. The problem is that the document that is being loaded does not end in and xml extension because it is a quesry string. I know that everything else is right but I get an "XML document must have a top level element". If I place the query string in the address window the correct xml file comes up.What is the deal? <BR><BR>mydoc.load("where this is a url quesry string not ending in xml")

  2. #2
    Join Date
    Dec 1969

    Default RE: load xml with asp

    Are you attempting to load do an SQL 2000 query in the Query string? If so I would recommend using an XML template file. In production you would want to disable adhoc queries through the query string.<BR><BR>If this is not the case ( the information below will be of no help, please provide more details. Otherwise, read on.) <BR>try this:<BR>(1) if you haven&#039;t created a Template directory, right click on the virtual directory and select properties, got to the virtual names tab and add a path to a new template folder.<BR>(2) create an xml template file similar to this:<BR><BR>&#060;?xml version =&#039;1.0&#039; encoding=&#039;UTF-8&#039;?&#062; <BR>&#060;root xmlns:sql=&#039;urn:schemas-microsoft-com:xml-sql&#039; <BR> sql:xsl=&#039;optional_XSLT.xsl&#039;&#062; <BR> &#060;sql:header&#062;<BR> &#060;sql:param&#062;EmployeeID&#060;/sql:param&#062;<BR> &#060;/sql:header&#062; <BR> &#060;sql:query&#062; <BR> SELECT * <BR> FROM Employees<BR> WHERE EmployeeID = @EmployeeID<BR> For XML Auto, Elements<BR> &#060;/sql:query&#062; <BR>&#060;/root&#062; <BR><BR>(3) save the above file as "getEmployee.xml" in the template folder.<BR>this will wrap the resulting XML in &#060;root&#062;&#060;/root&#062; tags this creates a top level element ("root").<BR><BR>you can then load the xml with the following server-side JScript:<BR>var xmldom = new ActiveXObject("Msxml2.DOMDocument.3.0");<BR> xmldom.async = false;<BR> xmldom.load("http://servername/NorthWind/templates/getEmployee.xml?EmployeeID=5");<BR> <BR>note the SQL parameter is passed in the QueryString.<BR><BR>this URL assumes that there is an SQL/IIS Virtual root called NorthWind with a subdirectory for templates called "templates" where the xml file "getEmployee.xml" is stored.<BR><BR>if you supply an XSL file for the attribute "sql:xsl" and you allow posts to the SQL/IIS virtual root you could avoid ASP all together by using the template URL as the value for the action attribute of an HTML form tag.<BR><BR>&#060;form action="http://servername/NorthWind/templates/getEmployee.xml" method="get"&#062;<BR>Enter Employee id<BR>&#060;input type="text" name="EmployeeID"&#062;<BR>&#060;input type="submit" value="submit"&#062;<BR>&#060;/form&#062;<BR><BR>onsubmit this will pass "EmployeeID" in the querystring to the template file and the XSLT transformed results will be returned to the client.<BR><BR>Hope this helps.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts