Hi, I already broke my head searching for a solution to this error
with no luck. That's why I'm requesting you guys help. I have one xml
that I want to validate against a xsd:
XSD:
<?xml version="1.0" encoding="iso-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="requerimentoCTc">
<xs:attribute name="numGuia" type="xs:string" />
<xs:attribute name="dataGuia" type="xs:date" />
<xs:attribute name="funcionarioGuia" type="xs:integer" />
</xs:complexType>
<xs:complexType name="requerenteCT">
<xs:attribute name="nome" type="xs:string" />
<xs:attribute name="docIdentificacao" type="xs:string" />
<xs:attribute name="docIDEmitidoPor" type="xs:string" />
<xs:attribute name="docIDdataEmissao" type="xs:date" />
<xs:attribute name="docIDValidade" type="xs:date" />
<xs:attribute name="nif" type="xs:integer" />
<xs:attribute name="domicilio" type="xs:string" />
<xs:attribute name="domicilioNum" type="xs:string" />
<xs:attribute name="freguesia" type="xs:string" />
<xs:attribute name="concelho" type="xs:string" />
<xs:attribute name="codPostal1" type="xs:integer" />
<xs:attribute name="codPostal2" type="xs:integer" />
<xs:attribute name="localidade" type="xs:string" />
<xs:attribute name="numTelefone" type="xs:string" />
<xs:attribute name="numfax" type="xs:string" />
<xs:attribute name="email" type="xs:string" />
<xs:attribute name="representacao" type="xs:string" />
<xs:attribute name="repNIF" type="xs:integer" />
<xs:attribute name="repDocIdentificacao" type="xs:string" />
<xs:attribute name="repDocIDEmitidoPor" type="xs:string" />
<xs:attribute name="repDocIDDataEmissao" type="xs:date" />
<xs:attribute name="repDocIDValidade" type="xs:date" />
</xs:complexType>
<xs:complexType name="documentoCT">
<xs:attribute name="id" type="xs:integer" />
<xs:attribute name="descricao" type="xs:string" />
<xs:attribute name="estado" type="xs:string" />
</xs:complexType>
<xs:complexType name="deferimentoCT">
<xs:attribute name="assinatura" type="xs:string" />
<xs:attribute name="dia" type="xs:integer" />
<xs:attribute name="ano" type="xs:integer" />
<xs:attribute name="mes" type="xs:string" />
</xs:complexType>
<xs:complexType name="optionCT">
<xs:sequence></xs:sequence>
<xs:attribute name="id" type="xs:integer" />
<xs:attribute name="descricao" type="xs:string" />
<xs:attribute name="estado" type="xs:string" />
</xs:complexType>
<xs:complexType name="requerimentoCTr">
<xs:sequence>
<xs:element name="instruccoes">
<xs:complexType>
<xs:sequence>
<xs:element name="optn" type="optionCT" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="numProcesso" type="xs:string" />
<xs:attribute name="funcionario" type="xs:string" />
<xs:attribute name="dataEmissao" type="xs:date" />
</xs:complexType>
</xs:schema>
<<<<<<<<<CUSTOM TYPES.XSD>>>>>>>>>>>>>>>
<?xml version="1.0" encoding="iso-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="requerimentoCTc">
<xs:attribute name="numGuia" type="xs:string" />
<xs:attribute name="dataGuia" type="xs:date" />
<xs:attribute name="funcionarioGuia" type="xs:integer" />
</xs:complexType>
<xs:complexType name="requerenteCT">
<xs:attribute name="nome" type="xs:string" />
<xs:attribute name="docIdentificacao" type="xs:string" />
<xs:attribute name="docIDEmitidoPor" type="xs:string" />
<xs:attribute name="docIDdataEmissao" type="xs:date" />
<xs:attribute name="docIDValidade" type="xs:date" />
<xs:attribute name="nif" type="xs:integer" />
<xs:attribute name="domicilio" type="xs:string" />
<xs:attribute name="domicilioNum" type="xs:string" />
<xs:attribute name="freguesia" type="xs:string" />
<xs:attribute name="concelho" type="xs:string" />
<xs:attribute name="codPostal1" type="xs:integer" />
<xs:attribute name="codPostal2" type="xs:integer" />
<xs:attribute name="localidade" type="xs:string" />
<xs:attribute name="numTelefone" type="xs:string" />
<xs:attribute name="numfax" type="xs:string" />
<xs:attribute name="email" type="xs:string" />
<xs:attribute name="representacao" type="xs:string" />
<xs:attribute name="repNIF" type="xs:integer" />
<xs:attribute name="repDocIdentificacao" type="xs:string" />
<xs:attribute name="repDocIDEmitidoPor" type="xs:string" />
<xs:attribute name="repDocIDDataEmissao" type="xs:date" />
<xs:attribute name="repDocIDValidade" type="xs:date" />
</xs:complexType>
<xs:complexType name="documentoCT">
<xs:attribute name="id" type="xs:integer" />
<xs:attribute name="descricao" type="xs:string" />
<xs:attribute name="estado" type="xs:string" />
</xs:complexType>
<xs:complexType name="deferimentoCT">
<xs:attribute name="assinatura" type="xs:string" />
<xs:attribute name="dia" type="xs:integer" />
<xs:attribute name="ano" type="xs:integer" />
<xs:attribute name="mes" type="xs:string" />
</xs:complexType>
<xs:complexType name="optionCT">
<xs:sequence></xs:sequence>
<xs:attribute name="id" type="xs:integer" />
<xs:attribute name="descricao" type="xs:string" />
<xs:attribute name="estado" type="xs:string" />
</xs:complexType>
<xs:complexType name="requerimentoCTr">
<xs:sequence>
<xs:element name="instruccoes">
<xs:complexType>
<xs:sequence>
<xs:element name="optn" type="optionCT" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="numProcesso" type="xs:string" />
<xs:attribute name="funcionario" type="xs:string" />
<xs:attribute name="dataEmissao" type="xs:date" />
</xs:complexType>
</xs:schema>
XML:
<?xml version="1.0" encoding="iso-8859-1" ?>
<licencaAutorizacaoObraEdificacao id="0">
<requerimentoC numGuia="" dataGuia="2001-01-01" funcionarioGuia="0" />
<requerimentoR numProcesso="" funcionario="" dataEmissao="2001-01-01">
<instruccoes>
<optn id="0" descricao="" estado="false" />
</instruccoes>
</requerimentoR><requerente nome="" docIdentificacao=""
docIDEmitidoPor="" docIDdataEmissao="2001-01-01"
docIDValidade="2001-01-01" nif="0" domicilio="" domicilioNum=""
freguesia="" concelho="" codPostal1="0" codPostal2="0" localidade=""
numTelefone="" numfax="" email="" representacao="" repNIF="0"
repDocIdentificacao="" repDocIDEmitidoPor=""
repDocIDDataEmissao="2001-01-01" repDocIDValidade="2001-01-01" />
<documento id="0" descricao="" estado="false" />
<deferimento assinatura="" dia="0" ano="0" mes="" />
<tipoOperacaoUrbanistica procPNum1="" procPNum2="" alvNum1=""
alvNum2="" numProc1="" numProc2="">
<operacoes>
<optnOP id="0" descricao="" estado="false" />
</operacoes>
<execucoes>
<optnEX id="0" descricao="" estado="false" />
</execucoes>
</tipoOperacaoUrbanistica><tipoEmpreendimentos>
<optnTE id="0" descricao="" estado="false" />
</tipoEmpreendimentos>
<exposicao qualidadeDo="" qualidadeDe="" sito="" numero=""
freguesia="" />
</licencaAutorizacaoObraEdificacao>
I'm using this algorithm to validate:
Dim reader As XmlValidatingReader = Nothing
Dim myschema As XmlSchemaCollection = New XmlSchemaCollection
validXMLFile = True
Try
Dim context As XmlParserContext = New
XmlParserContext(Nothing, Nothing, "", XmlSpace.None)
reader = New XmlValidatingReader(xmlText,
XmlNodeType.Element, context)
AddHandler reader.ValidationEventHandler, AddressOf
XmlValidatingError
myschema.Add(Nothing,
System.Web.HttpContext.Current.Server.MapPath("./xsd/Documentos/
Requerimentos/Requerimento_555.xsd"))
reader.ValidationType = ValidationType.Schema
reader.Schemas.Add(myschema)
While reader.Read
If Not validXMLFile Then
reader.Close()
Return False
End If
End While
reader.Close()
Return validXMLFile
Catch ex As XmlException
MessageBox.Show(ex.Message)
Return False
End Try
End Function
So...what's wrong? it's the XSD desgin? the validation algorithm?
Please, help me on this...
Regards,
Filipe Marcelino
Martin Honnen - 14 Nov 2007 14:29 GMT
> I'm using this algorithm to validate:
>
> Dim reader As XmlValidatingReader = Nothing
Are you using .NET 1.x? Otherwise you should not use XmlValidatingReader
but instead use an XmlReader created with XmlReader.Create and
XmlReaderSettings set to Validation.

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Filipe Marcelino - 14 Nov 2007 17:28 GMT
> > I'm using this algorithm to validate:
>
[quoted text clipped - 8 lines]
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
Hi,
yes, i'm using .net 1.1.
OK, i'll try.
Thanks
Martin Honnen - 14 Nov 2007 17:40 GMT
>>> I'm using this algorithm to validate:
>>> Dim reader As XmlValidatingReader = Nothing
>> Are you using .NET 1.x? Otherwise you should not use XmlValidatingReader
>> but instead use an XmlReader created with XmlReader.Create and
>> XmlReaderSettings set to Validation.
> yes, i'm using .net 1.1.
If you are using .NET 1.x then XmlValidatingReader is fine. I am not
sure what the problem is, do you get any errors?

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
gxdata - 25 Jan 2008 06:38 GMT
What's the error that you get? can you paste it into here so someone might
help you?
Your code does not declare some variables (eg, validXMLFile) but this is
Vb.NET so Option Explicit is OFF I assume?

Signature
Ian Thomas
> Hi, I already broke my head searching for a solution to this error
> with no luck. That's why I'm requesting you guys help. I have one xml
[quoted text clipped - 200 lines]
> Regards,
> Filipe Marcelino