default namespace / Xmlvalidatingreader
- From: "Plop69" <voorspoels@xxxxxxxxx>
- Date: 11 Apr 2006 02:48:59 -0700
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("tralalala"));
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("tralalala"));
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
.
- Follow-Ups:
- Re: default namespace / Xmlvalidatingreader
- From: Zafar Abbas
- Re: default namespace / Xmlvalidatingreader
- Prev by Date: XmlValidatingReader / Default Namespace
- Next by Date: XML deserialization (error)
- Previous by thread: XmlValidatingReader / Default Namespace
- Next by thread: Re: default namespace / Xmlvalidatingreader
- Index(es):
Relevant Pages
|
Loading