I get the following error when I try to validate XML against a
schema:
The 'http://www.w3.org/XML/1998/namespace:lang' attribute is not
declared
My questions are:
1. Why I am I getting this error?
2. How can I resolve?
I got the schema definition from a third party (ACORD).
I tried to do this using two different methods:
Method 1 – Using a LINQ XDoc (preferred way)
Private Function ValidXsd(ByVal AcordXml As String) As Boolean
Dim schemas As New XmlSchemaSet()
Dim returnVal As Boolean
schemas.Add(Nothing, XmlReader.Create(Server.MapPath("Includes \acord-pcs-v1_15_1-ns-nodoc-codes.xsd")))
Dim xDocAcordXml = XDocument.Load(New StringReader(AcordXml))
xDocAcordXml.Validate(schemas, AddressOf
ValidationEventHandler, True)
If SchemaValidationResults.Count = 0 Then
returnVal = True
Else
'Populate AcordXml with values in SchemaValidationResults
End If
Return returnVal
End Function
Sub ValidationEventHandler(ByVal sender As Object, ByVal e As System.Xml.Schema.ValidationEventArgs)
SchemaValidationResults.Add(e.Severity & ": " & e.Message)
End Sub
Method 2 – Using a XmlReader
Private Function ValidXsd2(ByVal AcordXml As String) As Boolean
Dim settings As New XmlReaderSettings()
Dim returnVal As Boolean
settings.Schemas.Add(Nothing, XmlReader.Create(Server.MapPath ("Includes\acord-pcs-v1_15_1-ns-nodoc-codes.xsd")))
settings.ValidationType = ValidationType.Schema
settings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings
AddHandler settings.ValidationEventHandler, AddressOf settings_ValidationEventHandler
settings.IgnoreWhitespace = True
settings.IgnoreComments = True
Using reader As XmlReader = XmlReader.Create(New StringReader (AcordXml), settings)
While (reader.Read())
'Empty loop
End While
End Using
If SchemaValidationResults.Count = 0 Then
returnVal = True
Else
'Populate AcordXml with values in SchemaValidationResults
End If
Return returnVal
End Function
' Display any warnings or errors.
Private Sub settings_ValidationEventHandler(ByVal sender As Object,
ByVal e As System.Xml.Schema.ValidationEventArgs)
SchemaValidationResults.Add(e.Severity & ": " & e.Message)
End Sub
I know the above code samples works since I tried them on a simple
example (XML, Schema). Plus I stole them from a book.
Any advice would be much appreciated.
Regards,
R
Le vendredi 17 avril 2009 16:00:00 UTC, Candle a écrit :
I get the following error when I try to validate XML against a
schema:
The 'http://www.w3.org/XML/1998/namespace:lang' attribute is not
declared
My questions are:
1. Why I am I getting this error?
2. How can I resolve?
I got the schema definition from a third party (ACORD).
I tried to do this using two different methods:
I know the above code samples works since I tried them on a simple
example (XML, Schema). Plus I stole them from a book.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 379 |
Nodes: | 16 (2 / 14) |
Uptime: | 40:15:09 |
Calls: | 8,141 |
Calls today: | 4 |
Files: | 13,085 |
Messages: | 5,857,618 |