Validating XML against XSD where XSD has includes

I have 2 Xsd's

The one contains basic type definitions

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
elementFormDefault="qualified" attributeFormDefault="unqualified">
 <xs:simpleType name="TrueFalse">
  <xs:restriction base="xs:NMTOKEN">
   <xs:enumeration value="true"/>
   <xs:enumeration value="false"/>
  </xs:restriction>
 </xs:simpleType>
</xs:schema>

The other includes the previous XSD so that the types declared can be used

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
elementFormDefault="qualified" attributeFormDefault="unqualified">
 <xs:include schemaLocation="Elements.xsd"/>
 <xs:element name="Events">
  <xs:complexType>
   <xs:sequence>
    <xs:element name="Source">
     <xs:simpleType>
      <xs:restriction base="xs:string"/>
     </xs:simpleType>
    </xs:element>
    <xs:element name="IsEstimatedDate" type="TrueFalse" minOccurs="0"/>
   </xs:sequence>
  </xs:complexType>
 </xs:element>
</xs:schema>


If I do this I can validate XML against the schema as below:
    Validator.Schema.Add("", @"C:\XSD\Event.xsd");

Validation Code:
    XmlParserContext Context = new XmlParserContext(null, null, "", 
XmlSpace.None);
    XmlValidatingReader Reader = new XmlValidatingReader(XMLStream, 
XmlNodeType.Element, Context);
    Reader.ValidationType = ValidationType.Schema;
    Reader.ValidationEventHandler += new 
ValidationEventHandler(ShowCompileErrors);
    Reader.Schemas.Add(Schema);
    etc

Validation works - no problem.
I assume that .Net knows how to find the Elements.xsd in the above case - 
becuase the Elements xsd sits in the same dir at the events xsd

Then:
I want to include the XSD's as an embedded resource in my .dll I have done 
this, and I have streamed the XSD

Running
XmlTextReader Xsdreader = new XmlTextReader(EventsXsdStream);
Validator.Schema.Add("", Xsdreader);

Result
Type 'TrueFalse' is not declared.

I then try to add the Elements.Xsd to the Schema collection before I add the
XmlTextReader Xsdreader = new XmlTextReader(ElementsXsdStream);
Validator.Schema.Add("", Xsdreader);

Result
Type 'TrueFalse' is not declared.

How should I load both XSD's so that the Events.xsd knows about the 
Elements.xsd and so that my validation will work correctly?

Thank you

--------------------------------
From: Brendon 


0
10/20/2004 10:57:09 PM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
752 Views

Similar Articles

[PageSpeed] 51

When you added Events.xsd from a file, the xs:include directive allowed it
to access components from Elements.xsd which was resolved using the baseURI
of Events.xsd, it worked since both schemas were in the same directory.

But now since you are loading them through a Stream, the basURI of
Events.xsd is not set, and it does not know where to resolve Elements.xsd
reference from. Notice that when you Add Events.xsd from a dll source as:

>XmlTextReader Xsdreader = new XmlTextReader(EventsXsdStream);
> Validator.Schema.Add("", Xsdreader);

it must through a validation warning through the event handler with the
error that schemaLocation could not be resolved, since it could not access
the Elements.xsd schema. In XmlSchemaCollection, you can add only one schema
from a namespace to the collection using Add ( ), so you can not Add both
schemas one by one to the collection and have it all work for you.

If you have both XSD sources in your DLL, you can load up both schemas in
XmlSchema objects using:

XmlSchema schema = XmlSchema.Read(new StreamReader(),
validationEventHandler);

and then set the schema.Includes property of the Events schema to point to
the Elements schema and then call schema.compile() for the Events schema.

In the .net framwork v2.0, a new schema store namely XmlSchemaSet is
present, which allows multiple adds of the schemas of the same namespace,
and this problem would not be present there.


Thanks.




"Brendon" <brendon@nospam.com> wrote in message
news:%23g2JDhvtEHA.3932@TK2MSFTNGP10.phx.gbl...
> I have 2 Xsd's
>
> The one contains basic type definitions
>
> <?xml version="1.0" encoding="utf-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified" attributeFormDefault="unqualified">
>  <xs:simpleType name="TrueFalse">
>   <xs:restriction base="xs:NMTOKEN">
>    <xs:enumeration value="true"/>
>    <xs:enumeration value="false"/>
>   </xs:restriction>
>  </xs:simpleType>
> </xs:schema>
>
> The other includes the previous XSD so that the types declared can be used
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified" attributeFormDefault="unqualified">
>  <xs:include schemaLocation="Elements.xsd"/>
>  <xs:element name="Events">
>   <xs:complexType>
>    <xs:sequence>
>     <xs:element name="Source">
>      <xs:simpleType>
>       <xs:restriction base="xs:string"/>
>      </xs:simpleType>
>     </xs:element>
>     <xs:element name="IsEstimatedDate" type="TrueFalse" minOccurs="0"/>
>    </xs:sequence>
>   </xs:complexType>
>  </xs:element>
> </xs:schema>
>
>
> If I do this I can validate XML against the schema as below:
>     Validator.Schema.Add("", @"C:\XSD\Event.xsd");
>
> Validation Code:
>     XmlParserContext Context = new XmlParserContext(null, null, "",
> XmlSpace.None);
>     XmlValidatingReader Reader = new XmlValidatingReader(XMLStream,
> XmlNodeType.Element, Context);
>     Reader.ValidationType = ValidationType.Schema;
>     Reader.ValidationEventHandler += new
> ValidationEventHandler(ShowCompileErrors);
>     Reader.Schemas.Add(Schema);
>     etc
>
> Validation works - no problem.
> I assume that .Net knows how to find the Elements.xsd in the above case -
> becuase the Elements xsd sits in the same dir at the events xsd
>
> Then:
> I want to include the XSD's as an embedded resource in my .dll I have done
> this, and I have streamed the XSD
>
> Running
> XmlTextReader Xsdreader = new XmlTextReader(EventsXsdStream);
> Validator.Schema.Add("", Xsdreader);
>
> Result
> Type 'TrueFalse' is not declared.
>
> I then try to add the Elements.Xsd to the Schema collection before I add
the
> XmlTextReader Xsdreader = new XmlTextReader(ElementsXsdStream);
> Validator.Schema.Add("", Xsdreader);
>
> Result
> Type 'TrueFalse' is not declared.
>
> How should I load both XSD's so that the Events.xsd knows about the
> Elements.xsd and so that my validation will work correctly?
>
> Thank you
>
> --------------------------------
> From: Brendon
>
>


0
zafara (79)
10/24/2004 7:17:27 AM
Reply:

Similar Artilces:

Msgbox entry validation
The following Macro will not loop more than twice the error entries. Will someone help me correct it to loop indefinely? Thanks Sub Entry_validation() Dim Teststring As String Dim Inputstring As String Cells(1, 1) = "ABC" 'as given filename Cells(2, 1) = "DEF" 'as given filename Cells(3, 1) = "GHI" 'as given filename Cells(4, 1) = "JKL" 'as given filename errorloop: Inputstring = InputBox(prompt:="Enter Filename" & vbLf & "Enter abort to abort en...

Data Validation -> Validation list is larger than the cell width
I have a workbook that I've just added data validation to one cell. FWIW, the data validation is based on a named range. Here's the (perceived) problem. When I've set up data validation in the past, the selection is the same width as the cell. In this case, the list starts almost a full cell width to the left. What am I missing? Thanks, Barb Reinhardt Barb, In Excel2003 I can replicate what you describe under the following conditions: 1. the named range contains entries that are wider than the data validation cell 2. The data validation cell is r...

Parsing XML in string variable?
I have a method that returns a string that contains XML, and I need to parse that string (ie. find specific keys). How can I do this? I found one that searches a Stream, but I don't know how to convert from string to stream. Thanks. hi vmi, you could use the System.Xml.XmlDocument class, simply make a new instance and use the LoadXml-Method (does not properly load string with encoding markers). You could also use the .NET 3.5 System.Xml.Linq.XElement. There are several utility classes to read from strings and streams and vice versa, e.g. System.IO.StringReader &am...

Insert XML string into XML File: Part 2
Thanks to some good help from a previous post, I have been able to create well formed xml as part of a report logger app. However, I still have a small problem. When I add new xml to the log file, the new nodes are appended to the original file. What I really want is for the log file to grow as "report nodes" are added. Also, I am a bit concerned about performance, particularly as the file grows in size. I must write to an xml file (vs. a database) and am trying to understand the best way to do this. I prefer to not use "temp files" and would like to just modify the ...

Validating against a DTD
Hello All, I am trying to validate an xml file against a DTD. I went through a lot of examples especially: http://www.xmlforasp.net/codebank/util/srcview.aspx?path=../../codebank/System_Xml/XmlValidatingReader/Validator/validator.src&file=validator.cs&font=3 but its not working in my case. First of all, when i try to add my DTD file in XmlSchemaCollection object, it throws an error saying DocType element is expected. I am using NITF DTD for this and there is no DocType element in it. Any help will be appreciated. Thanks. VD You should not add DTDs to XmlSchemaCollection. XmlSchema...

XML Tree Structure
Hi Folks, I would like to take a XML document and write its data into a tree structure for a custom tree control. The document has two fields with one called task (a text field) and the other called tree_level (an integer field). Consider the document to be valid and well-formed. The tree_level is an index describing where a node will reside in a tree structure. A partial view of the XML document is as follows: <task>summary task</task> <tree_level>0</tree_level> <task>task1</task> <tree_level>1</tree_level> <task>task2</task&...

Validation dropdown list is not coming visible
Hi, I'm using XP and 2003. I have a problem that I have once found resolution, but now it came again and cannot remember what needs to be done. Here is the problem: There is a column where Validation is specified in right manner with error message in case of error. When selecting the cell - dropdown list is not coming visible. In case I write something wrong it gives error message. If I recall correctly - it was something to do with some kind of list. How can I change this to work properly? I tried to paste new column from another file where the column is working as I want...

Data Validation
Hi all I want to set data validation on a cell so that it will accept the following (and only the following) text strings: (1) "BR" (literally) or (2) "NT" (literally) or (3) "nA" where n is any positive integral numerical value including zero and A may take any of the values "L", "P", "T", "V" or "Y" or (4) "An" where n is any positive integral numerical value including zero and A may take either of the values "K" or "D". Is this possible, please, and if so how? thanks -- Return e...

reinstall-validation problem
Hardware hit from lightning so new hd and video card and start over. All goes well with install using a slipstreamed XP-Pro SP3 disk but I notice it never asks for the Product Key during install yet it Activates itself during one of the boots and I think little of it until ... During the updates which followed (100+!!!) I notice Windows Defender doesn't seem to run or leave itself installed. As it is running on my laptop figured I just download it. When I run it, it wants to first do the Genuine Advantage bs which I let it, at which time it says "bogus". Ugh, g...

[ANN] Liquid XML Studio Released
Announcing the release of Liquid XML Studio 2008 a Freeware XML Development Environment. Download available from www.liquid-technologies.com. Key features include - An Advanced Graphical Schema Editor - XML Editor, with auto-complete, syntax highlighting & validation - Web Service Browser, supports calling Soap services - XPath Expression Builder, visualise XPath expressions - Documentation Generator, HTML Docs from your XML schemas - Code Generation, C++, C#, .Net, Java, VB .Net & VB6 (trial) Liquid XML...XML the smart way! ...

Validation
Julie the same can be achieve without going thru the double drop down boxes. You could do it just using the combobox alone. Thank again Please stay in the ORIGINAL thread. The archives will thank you. -- Don Guillett SalesAid Software donaldb@281.com "JLong" <anonymous@discussions.microsoft.com> wrote in message news:034101c49c3b$889b5020$a501280a@phx.gbl... > Julie the same can be achieve without going thru the > double drop down boxes. You could do it just using the > combobox alone. Thank again ...

Data Validation
I have set up a data form and have data validation rules on the various input cells. I see that there is an option called "Ignore blanks" in the data validation settings, which is supposed to restrict someone from entering past an input cell without entering valid data, if the "Ignore blanks" box is unchecked. I have tried to do this, but it does not seem to work. Please could someone tell me what I am doing wrong? Provide information, or better yet, a screen capture of the Data Validation dialog box with the Setting tab selected (User ALT+PrintScreen to copy the imag...

validating macro
Hi I am sending a spread sheet out to branchs I need them to complete a sheet (common info) before they do anything else on the workbook. I am looking for a macro or code for VBA which who check (common info) see if the cells are complete if not bring up a error screen informing the user to complete the form and then take them straight to the (common info) sheet. and if possible let them go to the tab which they want to go to. Use an extended version of something along these lines: (if there are lots of cells use a 'for row numbers x to y' or 'do until' statment, o...

How Do I parse this XML document, most efficiently?
What would be the best way to parse this XML document? I want to avoid using XMLDocument. I don't know if I should use XMLTextReader, or Xpath classes. There is only one element <MessageStore> element in the document, "always" at the end of the document. There will be thousands of <Messages> elements, "always" before <MessageStore> element. 1st Step ===== I need to get the <PR_STORE_ENTRY_ID> data "first". There will always only be one MessageStore element, with one child containing data. 2nd Step ====== I then need all the data from...

XML syntax as string
Hi I am trying to define string xml="<?xml version="1.0"?>"; But it gives error messages. Can any help me define <?xml version="1.0"?> as string... Thanks in advance Rahil string xml="<?xml version=\"1.0\"?>"; I hope it helps. >-----Original Message----- >Hi >I am trying to define >string xml="<?xml version="1.0"?>"; > >But it gives error messages. Can any help me define > ><?xml version="1.0"?> as string... > >Thanks in advance > >...

Generate XML from database and XSD files
Hi all, I have a set of XSD fiels: CSSTypes.xsd EventDetail.xsd E01_Export.xsd E02_Export.xsd E03_Export.xsd E04_Export.xsd E05_Export.xsd etc. I need to provide an exportation system of our database via external web service using sending the XML verified by the previous schemas. Any advise about how to proceed? what about XSD.EXE? is this usefull? Thank you very much, mc. ...

rules, dotnet applications and XML
<xml newbie> Hi all, We are considering using XML to specify rules, policies. This XML file will be used to generate source code in either managed C++ or C#, which will be implemention of API to be used by different applications program (written in .NET language, for this dicussion). You can contribute your ideas. Time for an example. A company or a government body has lot of policies which can be captured in the form of IF-THEN rules. These rules needs to be accomodated in application program(s). o Imagine an application program which processes visa applications, social security etc...

Reboot Validator
I'm running XP Pro, SP3. Attempting to install a program from Nero. Software keeps failing at startup, despite numerous re-installs. During installs, it keeps attempting to update the 'reboot validator' which it does not seem to be able to do. What is the reboot validator, and how do I update it. Couldn't find anything useful on MS site and Nero Tech support just says its an MS problem. -- Thank you, B. Parker Never heard of it but Nero Support should know about it: Reboot Validator appears to be a Nero component; cf. http://www.brighthub.com/comput...

Conditional validation?
Hello All I have a sheet that is essentially just columns of data (except for the column headings in the first row), and two of the columns are what I would call 'mutually exclusive': i.e. if a value is entered in a row in either column, the user must be prevented from entering any value in the same row of the other column. The two columns already have some basic validation applied (ranges of permissable numerical values), and this validation would need to be applied for any values that are entered. I am sure this can be done, but cannot see how! Hope someone can help. Many thanks L...

xsd:any help needed
I've got the following really simple schema : <?xml version="1.0" ?> <xs:schema targetNamespace="urn:503A2B4E-B364-47a4-AE5C-16E727275A70" xmlns:mstns="urn:503A2B4E-B364-47a4-AE5C-16E727275A70" xmlns="urn:503A2B4E-B364-47a4-AE5C-16E727275A70" xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified"> <xs:element name="SMSAdapter" > <xs:complexType> <xs:sequence> <xs:element name="phone" type=...

REPOST: dynamic validation
I think I wasn't clear that I need the Validation option under the Data menu, List, source values. That is what I am trying to fill with this equation. In other words, range1 and range2 are sets cells which contain values. I want those values to be the dropdown options in the cell based on what the previous cell to the left is selected as. So if Range1 is three cells with Tall, Dark, Handsome and Range2 is Sweet, Pretty, Nice, then based on the selection of F or M in A1, I want the choices for B1 to be one of those lists. I know that quotes are required for the IF. My probl...

Excel 2000 vs 2002 Sheet protection & Validation cells
Hello, I have an Excel spreadsheet built on Excel 2000. I have set sheet protection with password, and I have some unprotected cells with drop down menu (validation with 50 choices) Everything works very well. I sent this file to a friend who has Excel 2002. The same "unprotected" validation cells cannot be modified in his version as the message says that these cells are protected What can be done in order to make it work on his version?? I do have some "very hidden" sheet with password protected VBA properties, if that is an issue. Similarly there are some macros o...

Why can't I use XML in the Student and Teacher Edition?
Am I missing an Add-in? I can't believe I wasted my money buying this version of MS Office, when I can't even use it to complete the assignments when XML isn't available.. Any clues? Thanks, GunnyUSMCRet You've got one reply at one of your other posts. gunnyusmcret wrote: > > Am I missing an Add-in? I can't believe I wasted my money buying this version > of MS Office, when I can't even use it to complete the assignments when XML > isn't available.. > > Any clues? > > Thanks, > GunnyUSMCRet -- Dave Peterson XML is not available...

Typed Dataset as description of XML database?
I have read how one can define tables, indices, relations etc. in .Net code in a way that allows you to run a off-line XML based ADO.NET, which is excactly what I need. I have also read about Typed Dataset and hoiw this definition is stored in an XSD file. I was wondering if these two technologies can be used together or put in other words: Can I use the GUI tools in VS.Net to define the layout of my tables in order to desing my off-line XML database? Thank you in advance. All inputs on the issue is welcome. Best regards, Soeren Hello! > I was wondering if these two technologies...

How to use data validation
[NB: I re-structure my question since people got misled from my previous one] What I really wish to ask is: I wish to use data validation for a particular cell. But it doesn't work if I choose "custom" in the "allow" box. 1) In Data | Validation | Settings Tab | Validation Criteria, there is an "Allow" Box. 2) I chose "custom", there is a formula. 3) I type in some formula, eg: =J3 (Just Reference) =J3-J1 (Reference-type formula) =round(J1) (Function-type formula) None of them can activate the validation fu...