Accessing the PSVI value of xs:token types

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?TmljayBBcmRsaWU=?=

    Accessing the PSVI value of xs:token types

    Is there a way to access the PSVI value of xs:token types using C# (.NET
    Framework 2.0)?

    This issue has been around for some time (see
    http://lists.xml.org/archives/xml-de...msg00382.html). It appears that
    validation of token types now behaves correctly but the parser (e.g.
    XmlReader) still does not normalise the value (i.e. it is not PSVI enabled).

    In other words, is there a way to receive the following "test" element value
    (if defined in xml schema to be of type xs:token) as "A B C"? (its lexical
    value)

    <test A
    B
    C </test>



    Regards,
    Nick.
  • Martin Honnen

    #2
    Re: Accessing the PSVI value of xs:token types

    Nick Ardlie wrote:
    Is there a way to access the PSVI value of xs:token types using C# (.NET
    Framework 2.0)?
    >
    This issue has been around for some time (see
    http://lists.xml.org/archives/xml-de...msg00382.html). It appears that
    validation of token types now behaves correctly but the parser (e.g.
    XmlReader) still does not normalise the value (i.e. it is not PSVI enabled).
    >
    In other words, is there a way to receive the following "test" element value
    (if defined in xml schema to be of type xs:token) as "A B C"? (its lexical
    value)
    >
    <test A
    B
    C </test>

    Here is some sample code. XML document is

    <test>
    A
    B
    C
    </test>

    XML schema is

    <xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="test" type="xs:token"/>

    </xs:schema>

    C# code is

    XmlReaderSettin gs settings = new XmlReaderSettin gs();
    settings.Valida tionType = ValidationType. Schema;
    settings.Schema s.Add(null, @"..\..\XMLSche ma1.xsd");

    using (XmlReader reader =
    XmlReader.Creat e(@"..\..\XMLFi le2.xml", settings))
    {
    while (reader.Read())
    {
    if (reader.NodeTyp e == XmlNodeType.Ele ment &&
    reader.LocalNam e == "test")
    {
    Console.WriteLi ne("test content: |{0}|",
    reader.ReadElem entContentAsStr ing());
    }
    }
    }

    Output is

    test content: |A B C|

    so that value seems fine. Tested with .NET 3.5 however, will later test
    with .NET 2.0 too.



    --

    Martin Honnen --- MVP XML

    Comment

    • Martin Honnen

      #3
      Re: Accessing the PSVI value of xs:token types

      Martin Honnen wrote:
      Output is
      >
      test content: |A B C|
      >
      so that value seems fine. Tested with .NET 3.5 however, will later test
      with .NET 2.0 too.
      Result with .NET 2.0 is the same.

      --

      Martin Honnen --- MVP XML

      Comment

      • =?Utf-8?B?TmljayBBcmRsaWU=?=

        #4
        Re: Accessing the PSVI value of xs:token types

        Thanks Martin,

        That's exactly what I needed.

        Nick.

        "Martin Honnen" wrote:
        Martin Honnen wrote:
        >
        Output is

        test content: |A B C|

        so that value seems fine. Tested with .NET 3.5 however, will later test
        with .NET 2.0 too.
        >
        Result with .NET 2.0 is the same.
        >
        --
        >
        Martin Honnen --- MVP XML

        >

        Comment

        • =?Utf-8?B?TmljayBBcmRsaWU=?=

          #5
          Re: Accessing the PSVI value of xs:token types

          Out of interest, my confustion here stemmed from the content returned when
          the token type is invalid.
          I was testing an xs:token type that was (intentionally) invalid according to
          its type.
          E.g. Testing <testA B C </testwhere "test" is defined as type:

          <xs:simpleTyp e name="token2_Ty pe">
          <xs:restricti on base="xs:token" >
          <xs:minLength value="1"/>
          <xs:maxLength value="2"/>
          </xs:restriction>
          </xs:simpleType>

          Typically you wouldn't want to continue if the token value is invalid.
          But should you want to continue then the value returned is not normalized
          and you would have to do so manually.
          So it appears the PSVI property "[schema normalized value]" is either not
          created or not returned via the reader.ReadElem entContentAsStr ing() method
          invocation (in cases where the element content is not schema valid).
          My expectation for normalization in this case stemmed from the behaviour
          of Xerces-J.
          I suspect Xerces is just being helpful in this case as a quick review of
          the XML Schema spec suggests the [schema normalized value] does not have to
          be created
          when the item is not locally valid (?):

          (from http://www.w3.org/TR/xmlschema-1/)
          <quote>
          If clause 3 of Attribute Locally Valid (§3.2.4) applies with respect to an
          attribute information item, in the post-schema-validation infoset the
          attribute information item has a property: [schema normalized value]
          </quote>

          Regards,
          Nick.

          "Martin Honnen" wrote:
          Martin Honnen wrote:
          >
          Output is

          test content: |A B C|

          so that value seems fine. Tested with .NET 3.5 however, will later test
          with .NET 2.0 too.
          >
          Result with .NET 2.0 is the same.
          >
          --
          >
          Martin Honnen --- MVP XML

          >

          Comment

          Working...