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
|