467,174 Members | 1,340 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,174 developers. It's quick & easy.

Determine schemas used by document

Hi,

Using .Net 2.0 what is the best way to determine the list of schemas used by
a XmlDocument.

Thanks

Donal
May 17 '06 #1
  • viewed: 1911
Share:
5 Replies


Donal McWeeney wrote:
Using .Net 2.0 what is the best way to determine the list of schemas used by
a XmlDocument.


Each XmlDocument instance has a property named Schemas
<http://msdn2.microsoft.com/en-us/library/system.xml.xmldocument.schemas(VS.80).aspx>
Is that what you are looking for? Note sure what kind of "use" you have
in mind.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 17 '06 #2
Schemas is empty and only used (I think) for the purposes of validation.

I want to do two things:

- dynamically determine what schemas are referenced in a document so I can
build a XmlSchemaSet with the correct file paths to the actual schema files
for validating the document.

- check if a document uses a specific schema and if it does change that
schema name to a different schema...

Thanks

Donal

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:ug**************@TK2MSFTNGP05.phx.gbl...


Donal McWeeney wrote:
Using .Net 2.0 what is the best way to determine the list of schemas used
by a XmlDocument.


Each XmlDocument instance has a property named Schemas
<http://msdn2.microsoft.com/en-us/library/system.xml.xmldocument.schemas(VS.80).aspx>
Is that what you are looking for? Note sure what kind of "use" you have in
mind.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

May 18 '06 #3


Donal McWeeney wrote:
Schemas is empty and only used (I think) for the purposes of validation.

I want to do two things:

- dynamically determine what schemas are referenced in a document so I can
build a XmlSchemaSet with the correct file paths to the actual schema files
for validating the document.

So currently you simply load an XML document into an XmlDocument object
but you want to validate while loading using the xsi:schemaLocation (or
xsi:noNamespaceSchemaLocaton) hints in the document?
Then you need to use an XmlReader with the proper settings e.g.

XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.ValidationType = ValidationType.Schema;
readerSettings.ValidationFlags |=
XmlSchemaValidationFlags.ProcessSchemaLocation;
readerSettings.ValidationEventHandler += new
ValidationEventHandler(ValidationHandler);
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(XmlReader.Create(@"file.xml", readerSettings));
// now Schemas is a filled XmlSchemaSet
Console.WriteLine(xmlDocument.Schemas.Count);

I don't think there is any need to look for the schemas yourself, the
framework does that automatically if you use the proper settings as
shown above.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 18 '06 #4


Donal McWeeney wrote:
- check if a document uses a specific schema and if it does change that
schema name to a different schema...


Does that mean you want to read out the xsi:schemaLocation attribute and
then change its value?

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 18 '06 #5
Hi Martin,

thanks for the info...
- check if a document uses a specific schema and if it does change that
schema name to a different schema...


Does that mean you want to read out the xsi:schemaLocation attribute and
then change its value?


In this case changing the namespace name.

I dont think xsi:schemaLocation will work for me... thats why I have to do a
manual mapping.
May 18 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by anonymous@coolgroups.com | last post: by
3 posts views Thread by Modica82 | last post: by
6 posts views Thread by petermichaux@gmail.com | last post: by
5 posts views Thread by Robert Dufour | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.