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 23rd, 2006, 01:34 AM
Registered User
 
Join Date: Aug 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML parser error is not working in ASP

I have recieved some xml file which does not have the namespace and scemalocator defined in its root element. I have learned that, to validate the XML with any XSD, the XML file should have the above mentioned attribute in its root element. I have write an ASP code as follows but not getting the parsing error even if the XML file has the error.

The code is like this

<%
         Dim objDom
         Dim objRoot
         Dim objRecord
         Dim objField
         Dim objFieldValue
         Dim objattID
         Dim objattTabOrder
         Dim objPI
         Dim blnFileExists
         Dim x
              set xmlDoc = server.CreateObject("Microsoft.XMLDOM")
            xmlDoc.Load(server.MapPath("family.xml"))

           'Adding the attribute for namespace
                Set objRoot = xmlDoc.documentElement
        Set objRecord = xmlDoc.createAttribute("xmlns:xsi")
        objRecord.text="http://www.w3.org/2001/XMLSchema-instance"
        objRoot.setAttributeNode objRecord

'Adding the attribute for schema locator
        Set objRoot1 = xmlDoc.documentElement
        Set objNS = xmlDoc.createAttribute("xsi:noNamespaceSchemaLocat ion")
        objNS.text="http://localhost/dms/family.xsd"
        objRoot1.setAttributeNode objNS

             'I cannot save the modified xmlDoc in the machine
              'since the root element is read only.
            'SO loading the modifying XML document in another XMLDOM

        set xmlDoc1=server.CreateObject("Microsoft.XMLDOM")
        xmlDoc1.async = false
        xmlDoc1.resolveExternals = true
                xmlDoc1.validateOnParse=true
        xmlDoc1.load(xmlDoc)

             ' To check if the new DOM document has the new
             'scemalocator or not. It works file and shows
             'http://localhost/dms/family.xsd
    set objRoot2=xmlDoc1.documentElement
    vntVal=objRoot2.getAttribute("xsi:noNamespaceSchem aLocation")
        response.write vntVal

        Response.Write ("<br><p></p>")

        If xmlDoc1.parsed = True Then
          response.write("Parsed")
        else
          response.write("Not Parsed")
        end if

        'Now if the XML files does not have the defined
                'structure then an error should be there but having
                'no error.

        if xmlDoc1.parseError.reason <> "" then
              'set myErr = xmlDoc1.parseError
              response.write("You have error " )
         else
              response.write("No error ")
         end if
        End If
%>


Please give me a solution of this not in javascript but in Classic ASP. If there is any other way to add namespace and Schema locator to a root element then also let me know.

Regards
Bhaskar





Similar Threads
Thread Thread Starter Forum Replies Last Post
Xml parser testing Manoah XML 1 July 11th, 2008 04:10 AM
XML Parser alfatat SQL Language 0 March 29th, 2006 11:20 AM
XML Parser problems stephen_c_ Beginning PHP 0 July 11th, 2005 09:40 PM
XML File not found error from xerces parser P.J.Kim XML 0 October 19th, 2004 05:39 AM
XML Parser Problem?? mar0364 XML 1 September 15th, 2004 09:23 AM





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