sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
=?Utf-8?B?TmljayBBcmRsaWU=?='s Avatar

Accessing the PSVI value of xs:token types


Question posted by: =?Utf-8?B?TmljayBBcmRsaWU=?= (Guest) on August 21st, 2008 07:25 AM
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-d.../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.
4 Answers Posted
Martin Honnen's Avatar
Guest - n/a Posts
#2: Re: Accessing the PSVI value of xs:token types

Nick Ardlie wrote:
Quote:
Originally Posted by
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-d.../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's Avatar
Guest - n/a Posts
#3: Re: Accessing the PSVI value of xs:token types

Martin Honnen wrote:
Quote:
Originally Posted by
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=?='s Avatar
=?Utf-8?B?TmljayBBcmRsaWU=?= August 22nd, 2008 01:35 AM
Guest - n/a Posts
#4: Re: Accessing the PSVI value of xs:token types

Thanks Martin,

That's exactly what I needed.

Nick.

"Martin Honnen" wrote:
Quote:
Originally Posted by
Martin Honnen wrote:
>
Quote:
Originally Posted by
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=?='s Avatar
=?Utf-8?B?TmljayBBcmRsaWU=?= August 22nd, 2008 02:25 AM
Guest - n/a Posts
#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: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:
Originally Posted by
Martin Honnen wrote:
>
Quote:
Originally Posted by
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/
>

 
Not the answer you were looking for? Post your question . . .
197,027 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 197,027 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors