Re: default namespace / Xmlvalidatingreader



You dont get an exception in the case of the second file, since the element
TEST does not belong to any defined schema. Meaning a schema with the
targetnamespace of this element could not be found. Target namespace in this
case is an empty namespace.

In this case, there is no exception thrown from the validation reader, but a
validation warning should be thrown. You should attach a
ValidationEventHandler to the XmlValidatingReader to view the validation
errors and warnings both. If you dont attach a handler, you will only see
validation errors (as Exceptions) and will not see warnings at all.

Zafar
"Plop69" <voorspoels@xxxxxxxxx> wrote in message
news:1144748939.356751.310990@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
need some help on following:

xml file 1


<TEST xmlns="http://test"; >
<OK>mlkddflmkj</OK>
</TEST>


xml file 2


<TEST>
<OK>mlkddflmkj</OK>
</TEST>


at runtime i add the necessary xsd schema's.
now, these are files i receive from customer, so i can't change them.
When i read in the xml file 1 , it works like, it is validates against
the xsd's, and everything works fine.
when i read the second one, it doesn't validate, if i make sure the xml

file isn't valid, the xmlvalidatingreader doesn't notice it. So i
think it has something to do with : xmlns="http://test"; not being in
the second xml file.


So i tried to add it with a xmlparsercontext, but still it doesn't
work. How can i fix this?


the first xml file, goes trough this code and gives an exception when
file isn't valid, if the second xml file goes through this code, and
the file isn't valid it doesn't give an exception


public void Initialize(TextReader textReader)
{
XmlValidatingReader validatingReader = new
XmlValidatingReader(textReader);


validatingReader.Schemas.Add(XmlSchemaCache.GetInstance().GetSchema("tralal­
ala"));

validatingReader.Schemas.Add(schema);
validatingReader.ValidationType = ValidationType.Schema;


XmlReader readerToUse = validatingReader;


XPathDocument document = new XPathDocument(readerToUse); --> here it
throws exception if file isn't valid



}


this code i tried for the second xml file, so i add the default
namespace, but still i get no ecxeption when the xml file is invalid

public void Initialize(TextReader textReader)
{
XmlTextReader reader = new XmlTextReader(reader)
NameTable nt = reader.NameTable;
XmlNamespaceManager nsmgr = new XmlNamespaceManager(reader.NameTable);

nsmgr.AddNamespace(String.Empty, "http://test";);


XmlParserContext context = new XmlParserContext(reader.NameTable,
nsmgr, reader.XmlLang, reader.XmlSpace);


reader.MoveToContent();
XmlValidatingReader validatingReader = new
XmlValidatingReader(reader.ReadOuterXml(),XmlNodeType.Document,context);



validatingReader.Schemas.Add(XmlSchemaCache.GetInstance().GetSchema("tralal­
ala"));

validatingReader.Schemas.Add(schema);
validatingReader.ValidationType = ValidationType.Schema;


XmlReader readerToUse = validatingReader;


XPathDocument document = new XPathDocument(readerToUse); --> here it
DOES NOT throw exception if file isn't valid



}


now the funny thing is , in both functions when i put breakpoint on
this line:
XPathDocument document = new XPathDocument(readerToUse);
and check out the readerToUse object with QuickWatch, in the first
method above the default namespace isn't filled, but with the second
function it is filled (normal i think because i added it with the
xmlparsercontext).

So first i tought with adding the default namespace to the the
readerToUse object (in second function) it will work, till i saw that
the default namespace for the readerToUse object isn't filled in the
first function, so on what does the xmlvalidatingreader base itself for

validating the xmldocument???


i know this is a rather big and maybe difficult explanation of my
problem, so if there are questions please ask me, ANY help is weclom


.



Relevant Pages

  • Re: XmlValidatingReader / Default Namespace
    ... You dont get an exception in the case of the second file, ... validation warning should be thrown. ... XmlReader readerToUse = validatingReader; ...
    (microsoft.public.dotnet.xml)
  • XmlReader.Read produce an exception
    ... We get at the validation of an XML file against the corresponding schema ... The exception occurs also in the Visual Studio designer, ... Error list when the XML file is loaded with the schema. ...
    (microsoft.public.dotnet.xml)
  • Re: XmlReader.Read produce an exception
    ... We get at the validation of an XML file against the corresponding schema ... The exception occurs also in the Visual Studio designer, ... Error list when the XML file is loaded with the schema. ...
    (microsoft.public.dotnet.xml)
  • Re: Exceptions as return values
    ... The OP stated he derived his exception ... exception type, such as ArgumentException, rather then ApplicationException ... I like exposing the exception as a property of the validation class; ... derives from the base Exception class. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Frame-based exception handling problem on Server 2008
    ... appcompt shims to skip exception handlers validation for binaries ... the safe exception handler table has nothing to do with C++. ... Server, as well as on earlier Server versions, so it shouldn't have ...
    (microsoft.public.win32.programmer.kernel)