Cannot Validate XML with XSD created from stream.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob Mayo

    Cannot Validate XML with XSD created from stream.

    I have a bunch of XSD files in my assembly as embedded content that are read out via reflection and streams. My app creates the XML on the fly, and I want to validate it using the schema files embedded in my assembly.

    Unfortunately, my problem is that every element is coming up invalid.
    Here is the code:

    Public Sub Validate(ByVal XmlText As String)Dim strmXML As New System.IO.Memor yStream(System. Text.Encoding.U TF8.GetBytes(Xm lText))Dim xmlVR As New XmlValidatingRe ader(New XmlTextReader(s trmXML))Dim xmlValidationEv entHandler As Xml.Schema.Vali dationEventHand lerxmlValidatio nEventHandler = AddressOf ValidationEvent 'Read common & shared schemas (imported)'Dim xmlCommon As New Xml.Schema.XmlS chema()'xmlComm on.Read(FedEx.F edExManager.Rea dFedExSchema(Tr ansactionSchema .Common), xmlValidationEv entHandler)Dim xmlShared As New Xml.Schema.XmlS chema()xmlShare d.Read(FedEx.Fe dExManager.Read FedExSchema(Tra nsactionSchema. Shared), xmlValidationEv entHandler)xmlS hared.Compile(x mlValidationEve ntHandler)'Read specific schemaDim xmlSchema As New Xml.Schema.XmlS chema()xmlSchem a.Read(Me.m_str mSchema, xmlValidationEv entHandler)xmlS chema.TargetNam espace = "http://www.fedex.com/fsmapi"xmlSchem a.Compile(xmlVa lidationEventHa ndler)'xmlVR.Sc hemas.Add(xmlCo mmon)xmlVR.Sche mas.Add(xmlShar ed)xmlVR.Schema s.Add(xmlSchema )xmlVR.Validati onType = Xml.ValidationT ype.SchemaAddHa ndler xmlVR.Validatio nEventHandler, xmlValidationEv entHandlerWhile xmlVR.Read() 'Debug.WriteLin e(xmlVR.Name)En d WhileEnd Sub
  • Christoph Schittko [MVP]

    #2
    Re: Cannot Validate XML with XSD created from stream.

    Nothing jumps out at me right away. Have you tried to validate instance documents from both of the namespaces ( the FedEx one and the m_strmSchema one)?

    Did you make sure that the stream and the FedEx call returned valid schemas?

    Did you validate the instance document reading the schemas from a file?

    Can you post schemas and an instance document that fails to validate?



    --
    HTH
    Christoph Schittko [MVP, XmlInsider]
    Software Architect, .NET Mentor
    "Rob Mayo" <NOSPAM@NOSPAM. COM> wrote in message news:eo4KGCk1DH A.1304@TK2MSFTN GP10.phx.gbl...
    I have a bunch of XSD files in my assembly as embedded content that are read out via reflection and streams. My app creates the XML on the fly, and I want to validate it using the schema files embedded in my assembly.

    Unfortunately, my problem is that every element is coming up invalid.
    Here is the code:

    Public Sub Validate(ByVal XmlText As String) Dim strmXML As New System.IO.Memor yStream(System. Text.Encoding.U TF8.GetBytes(Xm lText))Dim xmlVR As New XmlValidatingRe ader(New XmlTextReader(s trmXML))Dim xmlValidationEv entHandler As Xml.Schema.Vali dationEventHand lerxmlValidatio nEventHandler = AddressOf ValidationEvent 'Read common & shared schemas (imported)'Dim xmlCommon As New Xml.Schema.XmlS chema()'xmlComm on.Read(FedEx.F edExManager.Rea dFedExSchema(Tr ansactionSchema .Common), xmlValidationEv entHandler) Dim xmlShared As New Xml.Schema.XmlS chema()xmlShare d.Read(FedEx.Fe dExManager.Read FedExSchema(Tra nsactionSchema. Shared), xmlValidationEv entHandler)xmlS hared.Compile(x mlValidationEve ntHandler) 'Read specific schemaDim xmlSchema As New Xml.Schema.XmlS chema()xmlSchem a.Read(Me.m_str mSchema, xmlValidationEv entHandler)xmlS chema.TargetNam espace = "http://www.fedex.com/fsmapi"xmlSchem a.Compile(xmlVa lidationEventHa ndler)'xmlVR.Sc hemas.Add(xmlCo mmon)xmlVR.Sche mas.Add(xmlShar ed)xmlVR.Schema s.Add(xmlSchema )xmlVR.Validati onType = Xml.ValidationT ype.Schema AddHandler xmlVR.Validatio nEventHandler, xmlValidationEv entHandler While xmlVR.Read() 'Debug.WriteLin e(xmlVR.Name)En d WhileEnd Sub

    Comment

    • Rob Mayo

      #3
      Generated XML

      <?xml version="1.0" encoding="UTF-8" ?>
      <FDXSubscriptio nRequest xmlns:api="http ://www.fedex.com/fsmapi" xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance" xsi:noNamespace SchemaLocation= "FDXSubscriptio nRequest.xsd">
      <RequestHeade r>
      <CustomerTransa ctionIdentifier >String</CustomerTransac tionIdentifier>
      <AccountNumber> 123456789</AccountNumber>
      </RequestHeader>
      <Contact>
      <PersonName>J im Smith</PersonName>
      <CompanyName>Cr eative Widgets</CompanyName>
      <Department>Shi pping</Department>
      <PhoneNumber>54 05559900</PhoneNumber>
      <PagerNumber>99 99999999</PagerNumber>
      <FaxNumber>5405 559901</FaxNumber>
      <E-MailAddress>jim @abc.com</E-MailAddress>
      </Contact>
      <Address>
      <Line1>123 Main Street</Line1>
      <Line2>1st Floor</Line2>
      <City>Anycity </City>
      <StateOrProvinc eCode>VA</StateOrProvince Code>
      <PostalCode>240 60</PostalCode>
      <CountryCode>US </CountryCode>
      </Address>
      </FDXSubscription Request>
      "Rob Mayo" <NOSPAM@NOSPAM. COM> wrote in message news:eo4KGCk1DH A.1304@TK2MSFTN GP10.phx.gbl...
      I have a bunch of XSD files in my assembly as embedded content that are read out via reflection and streams. My app creates the XML on the fly, and I want to validate it using the schema files embedded in my assembly.

      Unfortunately, my problem is that every element is coming up invalid.
      Here is the code:

      Public Sub Validate(ByVal XmlText As String) Dim strmXML As New System.IO.Memor yStream(System. Text.Encoding.U TF8.GetBytes(Xm lText))Dim xmlVR As New XmlValidatingRe ader(New XmlTextReader(s trmXML))Dim xmlValidationEv entHandler As Xml.Schema.Vali dationEventHand lerxmlValidatio nEventHandler = AddressOf ValidationEvent 'Read common & shared schemas (imported)'Dim xmlCommon As New Xml.Schema.XmlS chema()'xmlComm on.Read(FedEx.F edExManager.Rea dFedExSchema(Tr ansactionSchema .Common), xmlValidationEv entHandler) Dim xmlShared As New Xml.Schema.XmlS chema()xmlShare d.Read(FedEx.Fe dExManager.Read FedExSchema(Tra nsactionSchema. Shared), xmlValidationEv entHandler)xmlS hared.Compile(x mlValidationEve ntHandler) 'Read specific schemaDim xmlSchema As New Xml.Schema.XmlS chema()xmlSchem a.Read(Me.m_str mSchema, xmlValidationEv entHandler)xmlS chema.TargetNam espace = "http://www.fedex.com/fsmapi"xmlSchem a.Compile(xmlVa lidationEventHa ndler)'xmlVR.Sc hemas.Add(xmlCo mmon)xmlVR.Sche mas.Add(xmlShar ed)xmlVR.Schema s.Add(xmlSchema )xmlVR.Validati onType = Xml.ValidationT ype.Schema AddHandler xmlVR.Validatio nEventHandler, xmlValidationEv entHandler While xmlVR.Read() 'Debug.WriteLin e(xmlVR.Name)En d WhileEnd Sub

      Comment

      • Rob Mayo

        #4
        FDXSubscription Request.xsd

        <?xml version="1.0" encoding="UTF-8" ?>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:api="http ://www.fedex.com/fsmapi" elementFormDefa ult="qualified" >
        <!--<xs:include schemaLocation= "FDXShared. xsd" />-->
        <xs:element name="FDXSubscr iptionRequest">
        <xs:annotatio n>
        <xs:documentati on>
        <api:descriptio n>retrieves a meter number to be used in the customer's requests from a single location</api:description >
        <api:applicable Carriers>ALL</api:applicableC arriers>
        <api:validFor>A LL</api:validFor>
        </xs:documentatio n>
        </xs:annotation>
        <xs:complexType >
        <xs:sequence>
        <xs:element name="RequestHe ader" type="RequestHe ader">
        <xs:annotatio n>
        <xs:documentati on>
        <api:descriptio n>request boilerplate</api:description >
        <api:applicable Carriers>ALL</api:applicableC arriers>
        <api:validFor>A LL</api:validFor>
        </xs:documentatio n>
        </xs:annotation>
        </xs:element>
        <xs:element name="Contact" type="Contact">
        <xs:annotatio n>
        <xs:documentati on>
        <api:descriptio n>must match contact info on file for account</api:description >
        <api:applicable Carriers>ALL</api:applicableC arriers>
        <api:validFor>A LL</api:validFor>
        </xs:documentatio n>
        </xs:annotation>
        </xs:element>
        <xs:element name="Address" type="Address">
        <xs:annotatio n>
        <xs:documentati on>
        <api:descriptio n>must match address info on file for account</api:description >
        <api:applicable Carriers>ALL</api:applicableC arriers>
        <api:validFor>A LL</api:validFor>
        </xs:documentatio n>
        </xs:annotation>
        </xs:element>
        <xs:any minOccurs="0" maxOccurs="unbo unded" />
        </xs:sequence>
        </xs:complexType>
        </xs:element>
        </xs:schema>

        Comment

        • Rob Mayo

          #5
          FDXSubscription Request.xsd

          <?xml version="1.0" encoding="UTF-8" ?>
          <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:api="http ://www.fedex.com/fsmapi" elementFormDefa ult="qualified" >
          <!--<xs:include schemaLocation= "FDXShared. xsd" />-->
          <xs:element name="FDXSubscr iptionRequest">
          <xs:annotatio n>
          <xs:documentati on>
          <api:descriptio n>retrieves a meter number to be used in the customer's requests from a single location</api:description >
          <api:applicable Carriers>ALL</api:applicableC arriers>
          <api:validFor>A LL</api:validFor>
          </xs:documentatio n>
          </xs:annotation>
          <xs:complexType >
          <xs:sequence>
          <xs:element name="RequestHe ader" type="RequestHe ader">
          <xs:annotatio n>
          <xs:documentati on>
          <api:descriptio n>request boilerplate</api:description >
          <api:applicable Carriers>ALL</api:applicableC arriers>
          <api:validFor>A LL</api:validFor>
          </xs:documentatio n>
          </xs:annotation>
          </xs:element>
          <xs:element name="Contact" type="Contact">
          <xs:annotatio n>
          <xs:documentati on>
          <api:descriptio n>must match contact info on file for account</api:description >
          <api:applicable Carriers>ALL</api:applicableC arriers>
          <api:validFor>A LL</api:validFor>
          </xs:documentatio n>
          </xs:annotation>
          </xs:element>
          <xs:element name="Address" type="Address">
          <xs:annotatio n>
          <xs:documentati on>
          <api:descriptio n>must match address info on file for account</api:description >
          <api:applicable Carriers>ALL</api:applicableC arriers>
          <api:validFor>A LL</api:validFor>
          </xs:documentatio n>
          </xs:annotation>
          </xs:element>
          <xs:any minOccurs="0" maxOccurs="unbo unded" />
          </xs:sequence>
          </xs:complexType>
          </xs:element>
          </xs:schema>
          "Rob Mayo" <NOSPAM@NOSPAM. COM> wrote in message news:eo4KGCk1DH A.1304@TK2MSFTN GP10.phx.gbl...
          I have a bunch of XSD files in my assembly as embedded content that are read out via reflection and streams. My app creates the XML on the fly, and I want to validate it using the schema files embedded in my assembly.

          Unfortunately, my problem is that every element is coming up invalid.
          Here is the code:

          Public Sub Validate(ByVal XmlText As String) Dim strmXML As New System.IO.Memor yStream(System. Text.Encoding.U TF8.GetBytes(Xm lText))Dim xmlVR As New XmlValidatingRe ader(New XmlTextReader(s trmXML))Dim xmlValidationEv entHandler As Xml.Schema.Vali dationEventHand lerxmlValidatio nEventHandler = AddressOf ValidationEvent 'Read common & shared schemas (imported)'Dim xmlCommon As New Xml.Schema.XmlS chema()'xmlComm on.Read(FedEx.F edExManager.Rea dFedExSchema(Tr ansactionSchema .Common), xmlValidationEv entHandler) Dim xmlShared As New Xml.Schema.XmlS chema()xmlShare d.Read(FedEx.Fe dExManager.Read FedExSchema(Tra nsactionSchema. Shared), xmlValidationEv entHandler)xmlS hared.Compile(x mlValidationEve ntHandler) 'Read specific schemaDim xmlSchema As New Xml.Schema.XmlS chema()xmlSchem a.Read(Me.m_str mSchema, xmlValidationEv entHandler)xmlS chema.TargetNam espace = "http://www.fedex.com/fsmapi"xmlSchem a.Compile(xmlVa lidationEventHa ndler)'xmlVR.Sc hemas.Add(xmlCo mmon)xmlVR.Sche mas.Add(xmlShar ed)xmlVR.Schema s.Add(xmlSchema )xmlVR.Validati onType = Xml.ValidationT ype.Schema AddHandler xmlVR.Validatio nEventHandler, xmlValidationEv entHandler While xmlVR.Read() 'Debug.WriteLin e(xmlVR.Name)En d WhileEnd Sub

          Comment

          • Rob Mayo

            #6
            FDXShared.xsd

            <?xml version="1.0" encoding="UTF-8" ?>
            <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:api="http ://www.fedex.com/fsmapi" elementFormDefa ult="qualified" >
            <xs:complexTy pe name="RequestHe ader">
            <xs:sequence>
            <xs:element name="CustomerT ransactionIdent ifier" minOccurs="0" maxOccurs="1">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>freeform text that will be passed back in the response</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>Optional</api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            <xs:simpleTyp e>
            <xs:restricti on base="xs:string ">
            <xs:minLength value="1" />
            <xs:maxLength value="40" />
            </xs:restriction>
            </xs:simpleType>
            </xs:element>
            <xs:element name="AccountNu mber" type="AccountNu mber" minOccurs="0" maxOccurs="1">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>the FedEx Express Account Number of the sender</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>Required</api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            </xs:element>
            <xs:element name="MeterNumb er" type="MeterNumb er" minOccurs="0" maxOccurs="1">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>meter number of client</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>context-dependent; see particular transaction in XML Transaction Guide</api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            </xs:element>
            <xs:element name="CarrierCo de" type="CarrierCo de" minOccurs="0" maxOccurs="1">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>specifies a particular carrier</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>context-dependent; see particular transaction in XML Transaction Guide</api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            </xs:element>
            <xs:any minOccurs="0" maxOccurs="unbo unded" />
            </xs:sequence>
            </xs:complexType>
            <xs:complexTy pe name="ReplyHead er">
            <xs:sequence>
            <xs:element name="CustomerT ransactionIdent ifier" minOccurs="0" maxOccurs="1">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>freeform text that was passed in in the request</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>Optional</api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            <xs:simpleTyp e>
            <xs:restricti on base="xs:string ">
            <xs:minLength value="1" />
            <xs:maxLength value="40" />
            </xs:restriction>
            </xs:simpleType>
            </xs:element>
            <xs:any minOccurs="0" maxOccurs="unbo unded" />
            </xs:sequence>
            </xs:complexType>
            <xs:complexTy pe name="Error">
            <xs:sequence>
            <xs:element name="Code">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>error code returned when a transaction fails</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>Required</api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            <xs:simpleTyp e>
            <xs:restricti on base="xs:string ">
            <xs:minLength value="1" />
            <xs:maxLength value="8" />
            </xs:restriction>
            </xs:simpleType>
            </xs:element>
            <xs:element name="Message">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>error message returned when a transaction fails</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>Required</api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            <xs:simpleTyp e>
            <xs:restricti on base="xs:string ">
            <xs:minLength value="1" />
            <xs:maxLength value="120" />
            </xs:restriction>
            </xs:simpleType>
            </xs:element>
            <xs:any minOccurs="0" maxOccurs="unbo unded" />
            </xs:sequence>
            </xs:complexType>
            <xs:complexTy pe name="SoftError ">
            <xs:sequence>
            <xs:element name="Type" minOccurs="0" maxOccurs="1">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>TBD</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>Optional</api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            <xs:simpleTyp e>
            <xs:restricti on base="xs:string ">
            <xs:enumerati on value="WARNING" />
            <xs:enumerati on value="INFORMAT IONAL" />
            <xs:enumerati on value="SHIPPING _WARNING" />
            <xs:enumerati on value="SHIPPING _INFO" />
            <xs:enumerati on value="URSA_HAR D" />
            <xs:enumerati on value="URSA_SOF T" />
            </xs:restriction>
            </xs:simpleType>
            </xs:element>
            <xs:element name="Code">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>TBD</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>Required</api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            <xs:simpleTyp e>
            <xs:restricti on base="xs:string ">
            <xs:minLength value="1" />
            <xs:maxLength value="8" />
            </xs:restriction>
            </xs:simpleType>
            </xs:element>
            <xs:element name="Message">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>TBD</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>Required</api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            <xs:simpleTyp e>
            <xs:restricti on base="xs:string ">
            <xs:minLength value="1" />
            <xs:maxLength value="255" />
            </xs:restriction>
            </xs:simpleType>
            </xs:element>
            <xs:any minOccurs="0" maxOccurs="unbo unded" />
            </xs:sequence>
            </xs:complexType>
            <xs:complexTy pe name="Origin">
            <xs:sequence>
            <xs:element name="Contact" type="Contact">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>TBD</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            </xs:documentatio n>
            </xs:annotation>
            </xs:element>
            <xs:element name="Address" type="Address">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>TBD</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            </xs:documentatio n>
            </xs:annotation>
            </xs:element>
            <xs:any minOccurs="0" maxOccurs="unbo unded" />
            </xs:sequence>
            </xs:complexType>
            <xs:complexTy pe name="Contact">
            <xs:sequence>
            <xs:choice>
            <xs:sequence>
            <xs:element name="PersonNam e" type="PersonNam e">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>name of human being designated by sender as origin contact</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>Either this or Company Name or both must be specified</api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            </xs:element>
            <xs:element name="CompanyNa me" type="CompanyNa me" minOccurs="0" maxOccurs="1">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>name of company designated by sender for origin contact</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>Either this or Sender Contact Name or both must be specified</api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            </xs:element>
            </xs:sequence>
            <xs:element name="CompanyNa me" type="CompanyNa me">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>name of company designated by sender for origin contact</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>Either this or Sender Contact Name or both must be specified</api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            </xs:element>
            </xs:choice>
            <xs:element name="Departmen t" type="Departmen t" minOccurs="0" maxOccurs="1">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>name of department designated by sender for origin contact</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>Optional</api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            </xs:element>
            <xs:element name="PhoneNumb er" type="PhoneNumb er">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>sender contact phone number</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>Required</api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            </xs:element>
            <xs:element name="PagerNumb er" type="PhoneNumb er" minOccurs="0" maxOccurs="1">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>sender contact pager phone number</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>Optional</api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            </xs:element>
            <xs:element name="FaxNumber " type="PhoneNumb er" minOccurs="0" maxOccurs="1">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>sender contact fax machine phone number</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>Optional</api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            </xs:element>
            <xs:element name="E-MailAddress" type="E-MailAddress" minOccurs="0" maxOccurs="1">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>sender contact e-mail address</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>Optional. Required for Ship Alert</api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            </xs:element>
            <xs:any minOccurs="0" maxOccurs="unbo unded" />
            </xs:sequence>
            </xs:complexType>
            <xs:complexTy pe name="Payment">
            <xs:sequence>
            <xs:element name="PayorType " type="PayorType " minOccurs="0" maxOccurs="1">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>shipping charges payor type</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>Required</api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            </xs:element>
            <xs:element name="Payor" type="Payor" minOccurs="0" maxOccurs="1">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>TBD</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>
            <api:requiremen tsAndDependenci es>Required only if PayorType is "THIRDPARTY " or (for Express only) "RECIPIENT" </api:requirement sAndDependencie s>
            </xs:documentatio n>
            </xs:annotation>
            </xs:element>
            <xs:element name="CreditCar d" type="CreditCar d" minOccurs="0" maxOccurs="1">
            <xs:annotatio n>
            <xs:documentati on>
            <api:descriptio n>TBD</api:description >
            <api:applicable Carriers>ALL</api:applicableC arriers>
            <api:validFor>A LL</api:validFor>










            ........etc.

            Comment

            • Rob Mayo

              #7
              Re: Cannot Validate XML with XSD created from stream.

              I posted a document and the Schemas I'm using. Any thoughts?
              "Christoph Schittko [MVP]" <christophdotne tINVALID@austin .rr.com> wrote in message news:%23nO7JOm1 DHA.1752@tk2msf tngp13.phx.gbl. ..
              Nothing jumps out at me right away. Have you tried to validate instance documents from both of the namespaces ( the FedEx one and the m_strmSchema one)?

              Did you make sure that the stream and the FedEx call returned valid schemas?

              Did you validate the instance document reading the schemas from a file?

              Can you post schemas and an instance document that fails to validate?



              --
              HTH
              Christoph Schittko [MVP, XmlInsider]
              Software Architect, .NET Mentor
              "Rob Mayo" <NOSPAM@NOSPAM. COM> wrote in message news:eo4KGCk1DH A.1304@TK2MSFTN GP10.phx.gbl...
              I have a bunch of XSD files in my assembly as embedded content that are read out via reflection and streams. My app creates the XML on the fly, and I want to validate it using the schema files embedded in my assembly.

              Unfortunately, my problem is that every element is coming up invalid.
              Here is the code:

              Public Sub Validate(ByVal XmlText As String) Dim strmXML As New System.IO.Memor yStream(System. Text.Encoding.U TF8.GetBytes(Xm lText))Dim xmlVR As New XmlValidatingRe ader(New XmlTextReader(s trmXML))Dim xmlValidationEv entHandler As Xml.Schema.Vali dationEventHand lerxmlValidatio nEventHandler = AddressOf ValidationEvent 'Read common & shared schemas (imported)'Dim xmlCommon As New Xml.Schema.XmlS chema()'xmlComm on.Read(FedEx.F edExManager.Rea dFedExSchema(Tr ansactionSchema .Common), xmlValidationEv entHandler) Dim xmlShared As New Xml.Schema.XmlS chema()xmlShare d.Read(FedEx.Fe dExManager.Read FedExSchema(Tra nsactionSchema. Shared), xmlValidationEv entHandler)xmlS hared.Compile(x mlValidationEve ntHandler) 'Read specific schemaDim xmlSchema As New Xml.Schema.XmlS chema()xmlSchem a.Read(Me.m_str mSchema, xmlValidationEv entHandler)xmlS chema.TargetNam espace = "http://www.fedex.com/fsmapi"xmlSchem a.Compile(xmlVa lidationEventHa ndler)'xmlVR.Sc hemas.Add(xmlCo mmon)xmlVR.Sche mas.Add(xmlShar ed)xmlVR.Schema s.Add(xmlSchema )xmlVR.Validati onType = Xml.ValidationT ype.Schema AddHandler xmlVR.Validatio nEventHandler, xmlValidationEv entHandler While xmlVR.Read() 'Debug.WriteLin e(xmlVR.Name)En d WhileEnd Sub

              Comment

              • Christoph Schittko [MVP]

                #8
                Re: Cannot Validate XML with XSD created from stream.

                I'll take a look ... can you answer my questions?

                --
                HTH
                Christoph Schittko [MVP, XmlInsider]
                Software Architect, .NET Mentor
                "Rob Mayo" <NOSPAM@NOSPAM. COM> wrote in message news:uDZTBkv1DH A.1908@TK2MSFTN GP10.phx.gbl...
                I posted a document and the Schemas I'm using. Any thoughts?
                "Christoph Schittko [MVP]" <christophdotne tINVALID@austin .rr.com> wrote in message news:%23nO7JOm1 DHA.1752@tk2msf tngp13.phx.gbl. ..
                Nothing jumps out at me right away. Have you tried to validate instance documents from both of the namespaces ( the FedEx one and the m_strmSchema one)?

                Did you make sure that the stream and the FedEx call returned valid schemas?

                Did you validate the instance document reading the schemas from a file?

                Can you post schemas and an instance document that fails to validate?



                --
                HTH
                Christoph Schittko [MVP, XmlInsider]
                Software Architect, .NET Mentor
                "Rob Mayo" <NOSPAM@NOSPAM. COM> wrote in message news:eo4KGCk1DH A.1304@TK2MSFTN GP10.phx.gbl...
                I have a bunch of XSD files in my assembly as embedded content that are read out via reflection and streams. My app creates the XML on the fly, and I want to validate it using the schema files embedded in my assembly.

                Unfortunately, my problem is that every element is coming up invalid.
                Here is the code:

                Public Sub Validate(ByVal XmlText As String) Dim strmXML As New System.IO.Memor yStream(System. Text.Encoding.U TF8.GetBytes(Xm lText))Dim xmlVR As New XmlValidatingRe ader(New XmlTextReader(s trmXML))Dim xmlValidationEv entHandler As Xml.Schema.Vali dationEventHand lerxmlValidatio nEventHandler = AddressOf ValidationEvent 'Read common & shared schemas (imported)'Dim xmlCommon As New Xml.Schema.XmlS chema()'xmlComm on.Read(FedEx.F edExManager.Rea dFedExSchema(Tr ansactionSchema .Common), xmlValidationEv entHandler) Dim xmlShared As New Xml.Schema.XmlS chema()xmlShare d.Read(FedEx.Fe dExManager.Read FedExSchema(Tra nsactionSchema. Shared), xmlValidationEv entHandler)xmlS hared.Compile(x mlValidationEve ntHandler) 'Read specific schemaDim xmlSchema As New Xml.Schema.XmlS chema()xmlSchem a.Read(Me.m_str mSchema, xmlValidationEv entHandler)xmlS chema.TargetNam espace = "http://www.fedex.com/fsmapi"xmlSchem a.Compile(xmlVa lidationEventHa ndler)'xmlVR.Sc hemas.Add(xmlCo mmon)xmlVR.Sche mas.Add(xmlShar ed)xmlVR.Schema s.Add(xmlSchema )xmlVR.Validati onType = Xml.ValidationT ype.Schema AddHandler xmlVR.Validatio nEventHandler, xmlValidationEv entHandler While xmlVR.Read() 'Debug.WriteLin e(xmlVR.Name)En d WhileEnd Sub

                Comment

                • Christoph Schittko [MVP]

                  #9
                  Re: Cannot Validate XML with XSD created from stream.

                  Rob,

                  You're instance document not prefixing any elements is fine because the
                  schemas you posted do not define a targetNamespace that the type defintions
                  would belong to.

                  The FDXShared schema you posted is not complete which poses problems
                  reproducing your issue.

                  When I am trying to load the schemas your error I get the following error:

                  nhandled Exception: System.Xml.Sche ma.XmlSchemaExc eption: The content model
                  must be deterministic. Wildcard declaration along with a local element
                  declaration causes the content model to become ambiguous. An error occurred
                  at file:///D:/Documents and Settings/csc/My Documents/Visual Studio
                  Projects/c#/XmlSer/FDXShared.xsd, (4, 3).

                  Is this the same error and the same location that you are getting? If you
                  look at the schema you'll notice that most elements are defined to have some
                  defined elements plus arbitrary content: The complexType RequestHeader
                  element defines the children CustomTransacti onIdentifier, AccountNumber,
                  MeterNumber and CarrierCode, but because the compexType definition also
                  defines the <any> element, the RequestHeader can any other other element
                  from any namespace without invalidating the schema. One might argue that
                  this should not necessarily consititute a schema exception and abort the
                  validation process.

                  Maybe we get Dare's input if that's what's really happening and his opinion.

                  --
                  HTH
                  Christoph Schittko [MVP, XmlInsider]
                  Software Architect, .NET Mentor

                  "Rob Mayo" <NOSPAM@NOSPAM. COM> wrote in message
                  news:uB6na0T2DH A.2160@TK2MSFTN GP12.phx.gbl...
                  The problem is that all my instance documents don't have any elements that
                  are prefixed, so the don't reference the other namespaces.

                  When validating from files, I get an error that the schema is
                  non-deterministic. I have no Idea what this means.
                  "Christoph Schittko [MVP]" <christophdotne tINVALID@austin .rr.com> wrote in
                  message news:OhoFRF$1DH A.1752@tk2msftn gp13.phx.gbl...
                  I'll take a look ... can you answer my questions?

                  --
                  HTH
                  Christoph Schittko [MVP, XmlInsider]
                  Software Architect, .NET Mentor
                  "Rob Mayo" <NOSPAM@NOSPAM. COM> wrote in message
                  news:uDZTBkv1DH A.1908@TK2MSFTN GP10.phx.gbl...
                  I posted a document and the Schemas I'm using. Any thoughts?
                  "Christoph Schittko [MVP]" <christophdotne tINVALID@austin .rr.com> wrote in
                  message news:%23nO7JOm1 DHA.1752@tk2msf tngp13.phx.gbl. ..
                  Nothing jumps out at me right away. Have you tried to validate instance
                  documents from both of the namespaces ( the FedEx one and the m_strmSchema
                  one)?

                  Did you make sure that the stream and the FedEx call returned valid schemas?

                  Did you validate the instance document reading the schemas from a file?

                  Can you post schemas and an instance document that fails to validate?



                  --
                  HTH
                  Christoph Schittko [MVP, XmlInsider]
                  Software Architect, .NET Mentor
                  "Rob Mayo" <NOSPAM@NOSPAM. COM> wrote in message
                  news:eo4KGCk1DH A.1304@TK2MSFTN GP10.phx.gbl...
                  I have a bunch of XSD files in my assembly as embedded content that are read
                  out via reflection and streams. My app creates the XML on the fly, and I
                  want to validate it using the schema files embedded in my assembly.

                  Unfortunately, my problem is that every element is coming up invalid.
                  Here is the code:

                  Public Sub Validate(ByVal XmlText As String) Dim strmXML As New
                  System.IO.Memor yStream(System. Text.Encoding.U TF8.GetBytes(Xm lText))Dim xmlVR
                  As New XmlValidatingRe ader(New XmlTextReader(s trmXML))Dim
                  xmlValidationEv entHandler As
                  Xml.Schema.Vali dationEventHand lerxmlValidatio nEventHandler = AddressOf
                  ValidationEvent 'Read common & shared schemas (imported)'Dim xmlCommon As
                  New
                  Xml.Schema.XmlS chema()'xmlComm on.Read(FedEx.F edExManager.Rea dFedExSchema(Tr a
                  nsactionSchema. Common), xmlValidationEv entHandler) Dim xmlShared As New
                  Xml.Schema.XmlS chema()xmlShare d.Read(FedEx.Fe dExManager.Read FedExSchema(Tra n
                  sactionSchema.S hared),
                  xmlValidationEv entHandler)xmlS hared.Compile(x mlValidationEve ntHandler) 'Read
                  specific schemaDim xmlSchema As New
                  Xml.Schema.XmlS chema()xmlSchem a.Read(Me.m_str mSchema,
                  xmlValidationEv entHandler)xmlS chema.TargetNam espace =
                  "http://www.fedex.com/fsmapi"xmlSchem a.Compile(xmlVa lidationEventHa ndler)
                  'xmlVR.Schemas. Add(xmlCommon)x mlVR.Schemas.Ad d(xmlShared)xml VR.Schemas.Add( x
                  mlSchema)xmlVR. ValidationType = Xml.ValidationT ype.Schema AddHandler
                  xmlVR.Validatio nEventHandler, xmlValidationEv entHandler While xmlVR.Read()
                  'Debug.WriteLin e(xmlVR.Name)En d WhileEnd Sub


                  Comment

                  • Rob Mayo

                    #10
                    Re: Cannot Validate XML with XSD created from stream.

                    Yes, this is the error I get when I try to just validate via files.

                    "Christoph Schittko [MVP]" <christophdotne tINVALID@austin .rr.com> wrote in
                    message news:%23hGM7wm2 DHA.3196@TK2MSF TNGP11.phx.gbl. ..[color=blue]
                    > Rob,
                    >
                    > You're instance document not prefixing any elements is fine because the
                    > schemas you posted do not define a targetNamespace that the type[/color]
                    defintions[color=blue]
                    > would belong to.
                    >
                    > The FDXShared schema you posted is not complete which poses problems
                    > reproducing your issue.
                    >
                    > When I am trying to load the schemas your error I get the following error:
                    >
                    > nhandled Exception: System.Xml.Sche ma.XmlSchemaExc eption: The content[/color]
                    model[color=blue]
                    > must be deterministic. Wildcard declaration along with a local element
                    > declaration causes the content model to become ambiguous. An error[/color]
                    occurred[color=blue]
                    > at file:///D:/Documents and Settings/csc/My Documents/Visual Studio
                    > Projects/c#/XmlSer/FDXShared.xsd, (4, 3).
                    >
                    > Is this the same error and the same location that you are getting? If you
                    > look at the schema you'll notice that most elements are defined to have[/color]
                    some[color=blue]
                    > defined elements plus arbitrary content: The complexType RequestHeader
                    > element defines the children CustomTransacti onIdentifier, AccountNumber,
                    > MeterNumber and CarrierCode, but because the compexType definition also
                    > defines the <any> element, the RequestHeader can any other other element
                    > from any namespace without invalidating the schema. One might argue that
                    > this should not necessarily consititute a schema exception and abort the
                    > validation process.
                    >
                    > Maybe we get Dare's input if that's what's really happening and his[/color]
                    opinion.[color=blue]
                    >
                    > --
                    > HTH
                    > Christoph Schittko [MVP, XmlInsider]
                    > Software Architect, .NET Mentor
                    >
                    > "Rob Mayo" <NOSPAM@NOSPAM. COM> wrote in message
                    > news:uB6na0T2DH A.2160@TK2MSFTN GP12.phx.gbl...
                    > The problem is that all my instance documents don't have any elements that
                    > are prefixed, so the don't reference the other namespaces.
                    >
                    > When validating from files, I get an error that the schema is
                    > non-deterministic. I have no Idea what this means.
                    > "Christoph Schittko [MVP]" <christophdotne tINVALID@austin .rr.com> wrote in
                    > message news:OhoFRF$1DH A.1752@tk2msftn gp13.phx.gbl...
                    > I'll take a look ... can you answer my questions?
                    >
                    > --
                    > HTH
                    > Christoph Schittko [MVP, XmlInsider]
                    > Software Architect, .NET Mentor
                    > "Rob Mayo" <NOSPAM@NOSPAM. COM> wrote in message
                    > news:uDZTBkv1DH A.1908@TK2MSFTN GP10.phx.gbl...
                    > I posted a document and the Schemas I'm using. Any thoughts?
                    > "Christoph Schittko [MVP]" <christophdotne tINVALID@austin .rr.com> wrote in
                    > message news:%23nO7JOm1 DHA.1752@tk2msf tngp13.phx.gbl. ..
                    > Nothing jumps out at me right away. Have you tried to validate instance
                    > documents from both of the namespaces ( the FedEx one and the m_strmSchema
                    > one)?
                    >
                    > Did you make sure that the stream and the FedEx call returned valid[/color]
                    schemas?[color=blue]
                    >
                    > Did you validate the instance document reading the schemas from a file?
                    >
                    > Can you post schemas and an instance document that fails to validate?
                    >
                    >
                    >
                    > --
                    > HTH
                    > Christoph Schittko [MVP, XmlInsider]
                    > Software Architect, .NET Mentor
                    > "Rob Mayo" <NOSPAM@NOSPAM. COM> wrote in message
                    > news:eo4KGCk1DH A.1304@TK2MSFTN GP10.phx.gbl...
                    > I have a bunch of XSD files in my assembly as embedded content that are[/color]
                    read[color=blue]
                    > out via reflection and streams. My app creates the XML on the fly, and I
                    > want to validate it using the schema files embedded in my assembly.
                    >
                    > Unfortunately, my problem is that every element is coming up invalid.
                    > Here is the code:
                    >
                    > Public Sub Validate(ByVal XmlText As String) Dim strmXML As New
                    > System.IO.Memor yStream(System. Text.Encoding.U TF8.GetBytes(Xm lText))Dim[/color]
                    xmlVR[color=blue]
                    > As New XmlValidatingRe ader(New XmlTextReader(s trmXML))Dim
                    > xmlValidationEv entHandler As
                    > Xml.Schema.Vali dationEventHand lerxmlValidatio nEventHandler = AddressOf
                    > ValidationEvent 'Read common & shared schemas (imported)'Dim xmlCommon As
                    > New
                    >[/color]
                    Xml.Schema.XmlS chema()'xmlComm on.Read(FedEx.F edExManager.Rea dFedExSchema(Tr a[color=blue]
                    > nsactionSchema. Common), xmlValidationEv entHandler) Dim xmlShared As New
                    >[/color]
                    Xml.Schema.XmlS chema()xmlShare d.Read(FedEx.Fe dExManager.Read FedExSchema(Tra n[color=blue]
                    > sactionSchema.S hared),
                    > xmlValidationEv entHandler)xmlS hared.Compile(x mlValidationEve ntHandler)[/color]
                    'Read[color=blue]
                    > specific schemaDim xmlSchema As New
                    > Xml.Schema.XmlS chema()xmlSchem a.Read(Me.m_str mSchema,
                    > xmlValidationEv entHandler)xmlS chema.TargetNam espace =
                    > "http://www.fedex.com/fsmapi"xmlSchem a.Compile(xmlVa lidationEventHa ndler)
                    >[/color]
                    'xmlVR.Schemas. Add(xmlCommon)x mlVR.Schemas.Ad d(xmlShared)xml VR.Schemas.Add( x[color=blue]
                    > mlSchema)xmlVR. ValidationType = Xml.ValidationT ype.Schema AddHandler
                    > xmlVR.Validatio nEventHandler, xmlValidationEv entHandler While xmlVR.Read()
                    > 'Debug.WriteLin e(xmlVR.Name)En d WhileEnd Sub
                    >
                    >[/color]


                    Comment

                    Working...