Altova Mailing List Archives


Re: Namespaces with Schemas, How to validate

From: "Zafar Abbas [MSFT]" <zafara@---------.--->
To: NULL
Date: 8/11/2004 4:53:00 PM
Ryan,
The schema definitions in an XDR schema are "open" by default. They allow
any number of additional elements. Note that these elements do not impact
the outcome of validation.



"Ryan" <ryan-microsoft-public-xml@j...> wrote in message
news:%23szq7JkfEHA.1356@T......
> Zafar,
>
> This doesn't make sense!  Can you please explain?  How can the
> XmlValidatingReader know what a "<b:Rule.." element is?
>
> Sure, this element is declared in the BizTalkServer schema, but this is
only
> referenced as a namespace within the actual schema.
>
>     So I have my schema: call it 837P
>         which has a namespace: BizTalkServer
>
> Then there's my document, call it "X12_4010", which I want to validate
> against my "837P" schema.
>
> The XmlValidatingReader knows about the "<b:Rule" as it applies to the
837P
> schema... that makes sense...  but how does it know what to do with my
> document (what I've called "X12_4010")?  How does it know, for instance,
> that a <b:Rule type="any"> means that there MUST be a valid reference in
the
> children <b:Subject> elements?
>
> Thanks,
> Ryan
>
>
>
>
>
>
> "Zafar Abbas [MSFT]" <zafara@m...> wrote in message
> news:#yVbkYjfEHA.396@T......
> > It is done automatically by the schema. Just use the following code to
> > construct the validation reader:
> >
> > XmlTextReader tr = new XmlTextReader(XDR_FILE);
> > XmlValidatingReader vr = new XmlValidatingReader(tr);
> > vr.ValidationType = ValidationType.XDR;
> > vr.ValidationEventHandler += new
> ValidationEventHandler(ValidationCallback);
> > vr.Schemas.Add(String.Empty, XML_FILE);
> >
> > while(vr.Read())
> > {
> > }
> >
> >
> > "Ryan" <ryan-microsoft-public-xml@j...> wrote in message
> > news:%23YN0y3ifEHA.3428@T......
> > > Zafar, here is an example xml document that will be validated using
the
> > > already discussed schema.
> > >
> > > As mentioned in the previous message, the schema specifies:
> > >
> > > <ElementType name="TS837Q1__REF_TransmissionTypeIdentification"
> > >      content="empty" model="closed">
> > >   <description>Transmission Type Identification</description>
> > >   <b:RecordInfo tag_name="REF" structure="delimited"
> > >     delimiter_type="inherit_field" field_order="prefix"
> > >     count_ignore="no">
> > >       <b:Rule subjects="any">
> > >         <b:Subject name="@TS837Q1__REF02__TransmissionTypeCode" />
> > >         <b:Subject name="@NU_TS837Q1__REF03" />
> > >       </b:Rule>
> > >   </b:RecordInfo>
> > >
> > > Which is supposed to mean that the element named
> > > "TS837Q1__REF_TransmissionTypeIdentification" is only valid if it has
> > either
> > > a valid "TS837Q1__REF02__TransmissionTypeCode" attribute or a valid
> > > "@NU_TS837Q1__REF03" attribute.
> > >
> > > Again, my question is how can I perform this type of validating?  Is
> this
> > > handled automatically by the schema?  Or do I need a custom
> > parser/validator
> > > that "knows" how to handle <b:Rule... elements (and the other BizTalk
> > Schema
> > > elements)
> > >
> > > Thanks,
> > > Ryan
> > >
> > >
> > >
> > >
> > >
> > > "Zafar Abbas [MSFT]" <zafara@m...> wrote in message
> > > news:OwUFTCAfEHA.2812@t......
> > > > Ryan,
> > > > I think this is a valid XDR Schema. Could you please post the XML
you
> > are
> > > > trying to validate according to this XDR?
> > > >
> > > > Thanks.
> > > >
> > > > "Ryan" <ryan-microsoft-public-xml@j...> wrote in message
> > > > news:uZF6Cb7eEHA.1724@T......
> > > > > Zafar, the BizTalkServer schema is an XDR schema.  Can you please
> tell
> > > me
> > > > > how running the document through the validator would work?
> > > > >
> > > > > It uses uses it own elements and attributes to extend the schema
and
> > the
> > > > > "meaning" behind these additions is quite complex.  Please take a
> look
> > > at
> > > > > the attached schema that uses the BizTalkServer schema.
> > > > >
> > > > > There are elements like the following:
> > > > >
> > > > > <b:RecordInfo tag_name="REF" structure="delimited"
> > > > >   delimiter_type="inherit_field" field_order="prefix"
> > > > >   count_ignore="no">
> > > > >     <b:Rule subjects="any">
> > > > >       <b:Subject name="@TS837Q1__REF02__TransmissionTypeCode" />
> > > > >       <b:Subject name="@NU_TS837Q1__REF03" />
> > > > >     </b:Rule>
> > > > > </b:RecordInfo>
> > > > >
> > > > >
> > > > > This means that the containing ElementType must have either
> > > > > @TS837Q1__REF02__TransmissionTypeCode or @NU_TS837Q1__REF03
> specified
> > in
> > > > the
> > > > > document, otherwise there is an error.
> > > > >
> > > > > There are also elements like this:
> > > > >
> > > > > <AttributeType name="TS837Q1__REF02__TransmissionTypeCode"
> > > > >   d:type="string" d:maxLength="30" d:minLength="1">
> > > > >     <description>Transmission Type Code</description>
> > > > >     <b:FieldInfo edi_datatype="AN" justification="left" />
> > > > > </AttributeType>
> > > > >
> > > > >
> > > > > This "b:FieldInfo" element has nothing to do with validation of
the
> > XML,
> > > > > rather it is used when using the schema to convert a particular
XML
> > > > document
> > > > > to (or from) EDI format.
> > > > >
> > > > >
> > > > > There are also elements like this:
> > > > >
> > > > > - <ElementType name="TS837Q1_2430_CAS_LineAdjustment"
> content="empty"
> > > > > model="closed">
> > > > >   <description>Line Adjustment</description>
> > > > > - <b:RecordInfo tag_name="CAS" structure="delimited"
> > > > > delimiter_type="inherit_field" field_order="prefix"
> count_ignore="no">
> > > > > - <b:Rule subjects="any"
> > > > > qualifier="@TS837Q1_2430_CAS05__AdjustmentReasonCode">
> > > > >   <b:Subject name="@TS837Q1_2430_CAS06__AdjustmentAmount" />
> > > > >   <b:Subject name="@TS837Q1_2430_CAS07__AdjustmentQuantity" />
> > > > >   </b:Rule>
> > > > > - <b:Rule subjects="all"
> > > > qualifier="@TS837Q1_2430_CAS06__AdjustmentAmount">
> > > > >   <b:Subject name="@TS837Q1_2430_CAS05__AdjustmentReasonCode" />
> > > > >   </b:Rule>
> > > > > - <b:Rule subjects="all"
> > > > > qualifier="@TS837Q1_2430_CAS07__AdjustmentQuantity">
> > > > >   <b:Subject name="@TS837Q1_2430_CAS05__AdjustmentReasonCode" />
> > > > >   </b:Rule>
> > > > > - <b:Rule subjects="any"
> > > > > qualifier="@TS837Q1_2430_CAS08__AdjustmentReasonCode">
> > > > >   <b:Subject name="@TS837Q1_2430_CAS09__AdjustmentAmount" />
> > > > >   <b:Subject name="@TS837Q1_2430_CAS10__AdjustmentQuantity" />
> > > > >   </b:Rule>
> > > > >
> > > > > These "b:Rule"s must all validate and these happen to use a
special
> > > > > "qualifier" meaning that rule only need apply if there is a value
in
> > the
> > > > > qualifier.
> > > > >
> > > > > ###  Maybe I just didn't realize the power of schemas and there
> > ability
> > > to
> > > > > "automagically" perform these advanced types of validation.
> > > > >
> > > > >
> > > > > ###  Can you please still tell me about the
> > > schemas-microsoft-com:xml-data
> > > > > schema?  How does the validator enforce things like
d:type="string"
> or
> > > > > d:type="enumeration" with d:values="87 84 83".  Is this another
> > > > "automagic"
> > > > > ability of schemas?  Or is there hard-coded support for these
things
> > in
> > > > the
> > > > > XmlValidatingReader?
> > > > >
> > > > >
> > > > > Your response is very much appreciated!
> > > > >
> > > > > -Ryan
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > "Zafar Abbas [MSFT]" <zafara@m...> wrote in message
> > > > > news:%23eDsE7keEHA.2468@T......
> > > > > > Is the BizTalk Schema an XSD Schema? If it is just run another
> > > > validating
> > > > > > reader through the document with the ValidationType set to
Schema
> > and
> > > > the
> > > > > > BizTalk schema added to the Schemas collection.
> > > > > >
> > > > > > "Ryan" <ryan-microsoft-public-xml@j...> wrote in message
> > > > > > news:%238F4m3ceEHA.3428@T......
> > > > > > > Hi there, I've got a question that has gone unanswered and am
> > hoping
> > > > > that
> > > > > > > someone can give me a legitimate answer.
> > > > > > >
> > > > > > > My XDR schema looks like this:
> > > > > > >
> > > > > > > <Schema
> > > > > > >     name="X12_4010_837"
> > > > > > >     ....
> > > > > > >     xmlns="urn:schemas-microsoft-com:xml-data"
> > > > > > >     xmlns:b="urn:schemas-microsoft-com:BizTalkServer"
> > > > > > >     xmlns:d="urn:schemas-microsoft-com:datatypes">
> > > > > > > ....
> > > > > > > </Schema>
> > > > > > >
> > > > > > >
> > > > > > > Note the xmlns references.  I know (at least I think, please
> > correct
> > > > me
> > > > > if
> > > > > > > I'm wrong) that the .NET XmlValidatingReader has built-in
> support
> > > for
> > > > > the
> > > > > > > "xml-data" and "datatypes" schemas.  Support meaning that it
can
> > > > locate
> > > > > > > these schemas automatically and can "well-form validate".  Not
> > only
> > > > > that,
> > > > > > > but it can also interpret these schemas and perform "data
> > > validation"
> > > > > > >
> > > > > > > So for example, my schema looks like this
> > > > > > >
> > > > > > > ....
> > > > > > > <AttributeType
> > > > > > >     name="TS837Q1__REF02__TransmissionTypeCode"
> > > > > > >     d:type="string"
> > > > > > >     d:maxLength="30"
> > > > > > >     d:minLength="1">
> > > > > > >         <b:FieldInfo
> > > > > > >             edi_datatype="AN"
> > > > > > >             justification="left"/>
> > > > > > > </AttributeType>
> > > > > > > ...
> > > > > > >
> > > > > > >
> > > > > > > The XmlValidatingReader can locate the "datatypes" schema, so
it
> > > knows
> > > > > > that
> > > > > > > 'd:type="string"' and 'd:maxLenght="30"', etc. are
"well-formed"
> > and
> > > > are
> > > > > > > okay to be on a "AttributeType" element.  However, the reader
is
> > > also
> > > > > > smart
> > > > > > > enough to be able to throw an error if in my actual xml
> document,
> > > this
> > > > > > > particular attribute has a length greater than 30 or less than
> 1.
> > > > > > >
> > > > > > > All this validation happens when I simply do:
> > > > > > >
> > > > > > >     XmlValidatingReader reader =
> > > > > > >         new XmlValidatingReader(
> > > > > > >             new XmlTextReader(filename));
> > > > > > >     while (reader.Read());
> > > > > > >
> > > > > > > So, the "xml-data" and "datatypes" schemas are completely
> handled
> > by
> > > > the
> > > > > > > XmlValidatingReader, but now I need to handle the
> "BizTalkServer"
> > > > > schema!
> > > > > > > How can I do this?
> > > > > > >
> > > > > > > Must I build in my validator some code that essentially does:
> > > > > > >
> > > > > > >     1. first-pass validate using just a XmlValidatingReader
> > > > > > >     2. second-pass walking each node and enforcing the rules
of
> > the
> > > > > > > BizTalkServer schema on my document.
> > > > > > >
> > > > > > > Or, is it possible (and better practice?) to extend
> > > > XmlValidatingReader
> > > > > > and
> > > > > > > try to validate the Xml document during Read() requests.
> > > > > > >
> > > > > > > Thanks for your help!
> > > > > > >
> > > > > > > -Ryan
> > > > > > >
> > > > > > >
> > > > > > > p.s. What would happen if I tried to port to Xerces (not that
> I'd
> > > > really
> > > > > > > want to :)  Would I have to add my own custom support for the
> > > > microsoft
> > > > > > > "xml-data" and "datatypes" schemas as well?
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
>
>


Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.