Connecting Tech Pros Worldwide Help | Site Map

Accessing the PSVI value of xs:token types

=?Utf-8?B?TmljayBBcmRsaWU=?=
Guest
 
Posts: n/a
#1: Aug 21 '08
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
Guest
 
Posts: n/a
#2: Aug 21 '08

re: Accessing the PSVI value of xs:token types


Nick Ardlie wrote:
Quote:
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

XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add(null, @"..\..\XMLSchema1.xsd");

using (XmlReader reader =
XmlReader.Create(@"..\..\XMLFile2.xml", settings))
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element &&
reader.LocalName == "test")
{
Console.WriteLine("test content: |{0}|",
reader.ReadElementContentAsString());
}
}
}

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
http://JavaScript.FAQTs.com/
Martin Honnen
Guest
 
Posts: n/a
#3: Aug 21 '08

re: Accessing the PSVI value of xs:token types


Martin Honnen wrote:
Quote:
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
http://JavaScript.FAQTs.com/
=?Utf-8?B?TmljayBBcmRsaWU=?=
Guest
 
Posts: n/a
#4: Aug 22 '08

re: Accessing the PSVI value of xs:token types


Thanks Martin,

That's exactly what I needed.

Nick.

"Martin Honnen" wrote:
Quote:
Martin Honnen wrote:
>
Quote:
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
http://JavaScript.FAQTs.com/
>
=?Utf-8?B?TmljayBBcmRsaWU=?=
Guest
 
Posts: n/a
#5: Aug 22 '08

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:simpleType name="token2_Type">
<xs:restriction 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.ReadElementContentAsString() 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:
Quote:
Martin Honnen wrote:
>
Quote:
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
http://JavaScript.FAQTs.com/
>
Closed Thread