473,395 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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
5 2139


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tony Prichard | last post by:
Hi I would like to specify an XML schema that would allow an XML document to be included within another XML document. The following example schema gives an idea of what we're trying to achieve ...
0
by: kyancy | last post by:
Hello All. We have several XML schemas to describe common component document parts. We then create new XML schemas as necessary that use "xsd:import schemaLocation=whateverLocation.." to include...
0
by: Steve Jorgensen | last post by:
I recently produced an XML Schema to support several kinds of transactions within a particular business domain. In the process, I learned pretty much all of how W3C XML Schema works, learned some...
4
by: anonymous | last post by:
When I use the schema collection to apply many schemas to one XML instance document, I get an error if I do not qualify every element with the appropriate namespace. Both the W3C site and this...
3
by: Modica82 | last post by:
Hi All, I am in the process of designing a web service for my company. It is my first commercial web service, so i think my "Hello World" coding model wont quite cut it here :). Anyway, i am...
6
by: petermichaux | last post by:
Hi, Is there a way to determine the name of a JavaScript file from inside the very same file? Thanks, Peter
3
by: M Borkan | last post by:
Can anyone tell me how to access the encodingStyle in a client from a SoapExtension? In particular, I'd like to know the style in SoapClientMessage in the SoapMessageStage.BeforeSerialize. I'm...
5
by: Robert Dufour | last post by:
With system.web.mail in VS2003, doing some tests, using localhost from IIS as server, I noticed that my code queues the messages OK, but when changing sender addresses I see that the mail message...
3
by: Water Cooler v2 | last post by:
Sorry for asking this beginner question. I've written DTDs so far and read about XML Schemas. I understand that they are a replacement of the DTD fundamentally, and therefore allow for the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.