default namespace / Xmlvalidatingreader



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

  • XmlValidatingReader / Default Namespace
    ... file isn't valid, if the second xml file goes through this code, and ... XmlValidatingReader validatingReader = new ... and check out the readerToUse object with QuickWatch, ...
    (microsoft.public.dotnet.xml)
  • Re: populate many xml file into single dataset
    ... method in dataadapter but no xml file. ... modify the code to allow to read the second xml file to the dataset? ... class TestXML{ ... public static void Main{ ...
    (microsoft.public.dotnet.framework.adonet)
  • XML Web Part support for XSLT Document() function
    ... I have produced an XSLT file that includes a second XML file into a ... While the XSLT works works in Internext Explorer and other ... transform.xsl - the XSLT file ...
    (microsoft.public.sharepoint.portalserver)
  • Is this a bug?
    ... Create a new project with the general working times as 24 hours and when it ... If you close Project down and then reopen it and load the second xml file ... Tristan ...
    (microsoft.public.project)

Loading