You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Christian Schuhegger <Ch...@gmx.de> on 2003/10/21 17:17:50 UTC
Re: accessing schema validated values
Hello,
Elena Litani wrote:
> Currently it is not possible to access actual values via any of the API.
> Normally, you can access extra XML Schema information via PSVI API (e.g.
> normalized value, element type, etc.) [1]**. The PSVI can be accessed
> via DOM/SAX in Xerces.
>
> We are thinking to add getActualValue() on the ItemPSVI that would
> return an object representing actual value. However, currently actual
> values have Xerces internal representation (in
> org.apache.xerces.impl.dv.xs classes). Would it be useful to you if we
> exposed those values? What kind of information would you like to
> retrieve from these internal representations, e.i. what kind of methods
> would you like to see?
I have exactly the same problem. After validating my document I would
like to be able to access actual values of attributes or elements as
their real Java data-type, e.g. I would like to have a way to get a
value of type xs:integer as an actual Java Integer object, the same for
Date, Double, ...
Therefore the internal data representation is not very useful for that
purpose, e.g. I had a look at the XDecimal class and I cannot get from
that class a Java Integer object.
Your proposal to expose the validated values in the ItemPSVI classes
sounds like a very good idea to me. Perhaps it is possible to extend the
internal data representation classes like the XDecimal to return actual
Java object representations of the basic types in parallel to extend the
ItemPSVI interfaces?
While I am just writing this e-mail I would also like to ask if there is
a way to perform partial validation of XML documents? I mean, I have
only seen a normalizeDocument() method on the Document class, but what I
would like to be able to do is to validate parts of a document below the
document root, too. Is there a way to achieve that? Or is this feature
perhaps planned for a future release?
Thanks a lot!!
--
Christian Schuhegger
http://galileo.spaceports.com/~cschuheg
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: accessing schema validated values
Posted by Geoff Granum <gr...@purdue.edu>.
Novice here, but how about setting a constant when the wrapper Object is
created such that one can call a function and get an integer constant which
represents the data type. For example
public static final int DOUBLE = 0, INT = 1, BOOLEAN = 2 ... etc;
protected int validatedValueType = -1;
public int getValidatedValueType() throws ...{
if(validatedValueType == -1){
throw new some_NotInitiatedException();
}
return validatedValueType
}
The value of validatedValueType is set when the Object representing the
actual ValidatedValue is set.
Just a thought.
--
Geoff Granum
granum@purdue.edu
Aeronautical & Astronautical Engineering,
Purdue University
West Lafayette, Indiana
On Tue, 21 Oct 2003 17:29:18 -0400, Elena Litani <el...@ca.ibm.com>
wrote:
> Hi Christian,
>
> Thank you for your reply.
>
> Christian Schuhegger wrote:
>
>> Your proposal to expose the validated values in the ItemPSVI classes
>> sounds like a very good idea to me. Perhaps it is possible to extend the
>> internal data representation classes like the XDecimal to return actual
>> Java object representations of the basic types in parallel to extend the
>> ItemPSVI interfaces?
>
> I believe the ItemPSVI interface should have only one method that
> returns an Object representing the actual value. Given that, you will
> need to have bunch of instanceof checks in your code to be able to cast
> to the internal Xerces representation, i.e. XDecimal, and then get a
> Java decimal (a method could be defined on XDecimal). Are you fine with
> this solution?
>
> There are couple of alternative solutions, so if you want to discuss it
> lets do it on the xerces-j-dev mailing list.
>
>
>> While I am just writing this e-mail I would also like to ask if there is
>> a way to perform partial validation of XML documents? I mean, I have
>> only seen a normalizeDocument() method on the Document class, but what I
>> would like to be able to do is to validate parts of a document below the
>> document root, too. Is there a way to achieve that? Or is this feature
>> perhaps planned for a future release?
>
> See email below.
>
> Thank you,
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
Re: accessing schema validated values
Posted by Christian Schuhegger <Ch...@gmx.de>.
Hi Elena,
> I believe the ItemPSVI interface should have only one method that
> returns an Object representing the actual value. Given that, you will
> need to have bunch of instanceof checks in your code to be able to cast
> to the internal Xerces representation, i.e. XDecimal, and then get a
> Java decimal (a method could be defined on XDecimal). Are you fine with
> this solution?
I think it is not enough to just return the actual Java object, because
when I use in my document an Integer with min/max constraints then in
effect I have a domain type that restricts its valid values to a subset
of what the underlying base type would allow. At some place I would like
to be able to find out to which domain type the value I got belongs to.
I would imagine to get from ItemPSVI something like a "TypedValue" (i
don't care about the name of that class) object where there is a method
to get the host language value plus a method to be able to find out more
about the domain of that value, e.g.:
public interface TypedValue {
public Object getHostLanguageValue();
public XSTypeDefinition getTypeDefinition();
}
With that approach somebody who is not interested in the domain type
does not need to have a casting cascade, he just gets the host language
value and continues to work with that value.
>>While I am just writing this e-mail I would also like to ask if there is
>>a way to perform partial validation of XML documents? I mean, I have
>>only seen a normalizeDocument() method on the Document class, but what I
>>would like to be able to do is to validate parts of a document below the
>>document root, too. Is there a way to achieve that? Or is this feature
>>perhaps planned for a future release?
>
>
> See email below.
Thanks for that info!
Have a nice day,
--
Christian Schuhegger
http://galileo.spaceports.com/~cschuheg
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
Re: accessing schema validated values
Posted by Geoff Granum <gr...@purdue.edu>.
Novice here, but how about setting a constant when the wrapper Object is
created such that one can call a function and get an integer constant which
represents the data type. For example
public static final int DOUBLE = 0, INT = 1, BOOLEAN = 2 ... etc;
protected int validatedValueType = -1;
public int getValidatedValueType() throws ...{
if(validatedValueType == -1){
throw new some_NotInitiatedException();
}
return validatedValueType
}
The value of validatedValueType is set when the Object representing the
actual ValidatedValue is set.
Just a thought.
--
Geoff Granum
granum@purdue.edu
Aeronautical & Astronautical Engineering,
Purdue University
West Lafayette, Indiana
On Tue, 21 Oct 2003 17:29:18 -0400, Elena Litani <el...@ca.ibm.com>
wrote:
> Hi Christian,
>
> Thank you for your reply.
>
> Christian Schuhegger wrote:
>
>> Your proposal to expose the validated values in the ItemPSVI classes
>> sounds like a very good idea to me. Perhaps it is possible to extend the
>> internal data representation classes like the XDecimal to return actual
>> Java object representations of the basic types in parallel to extend the
>> ItemPSVI interfaces?
>
> I believe the ItemPSVI interface should have only one method that
> returns an Object representing the actual value. Given that, you will
> need to have bunch of instanceof checks in your code to be able to cast
> to the internal Xerces representation, i.e. XDecimal, and then get a
> Java decimal (a method could be defined on XDecimal). Are you fine with
> this solution?
>
> There are couple of alternative solutions, so if you want to discuss it
> lets do it on the xerces-j-dev mailing list.
>
>
>> While I am just writing this e-mail I would also like to ask if there is
>> a way to perform partial validation of XML documents? I mean, I have
>> only seen a normalizeDocument() method on the Document class, but what I
>> would like to be able to do is to validate parts of a document below the
>> document root, too. Is there a way to achieve that? Or is this feature
>> perhaps planned for a future release?
>
> See email below.
>
> Thank you,
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: accessing schema validated values
Posted by Christian Schuhegger <Ch...@gmx.de>.
Hi Elena,
> I believe the ItemPSVI interface should have only one method that
> returns an Object representing the actual value. Given that, you will
> need to have bunch of instanceof checks in your code to be able to cast
> to the internal Xerces representation, i.e. XDecimal, and then get a
> Java decimal (a method could be defined on XDecimal). Are you fine with
> this solution?
I think it is not enough to just return the actual Java object, because
when I use in my document an Integer with min/max constraints then in
effect I have a domain type that restricts its valid values to a subset
of what the underlying base type would allow. At some place I would like
to be able to find out to which domain type the value I got belongs to.
I would imagine to get from ItemPSVI something like a "TypedValue" (i
don't care about the name of that class) object where there is a method
to get the host language value plus a method to be able to find out more
about the domain of that value, e.g.:
public interface TypedValue {
public Object getHostLanguageValue();
public XSTypeDefinition getTypeDefinition();
}
With that approach somebody who is not interested in the domain type
does not need to have a casting cascade, he just gets the host language
value and continues to work with that value.
>>While I am just writing this e-mail I would also like to ask if there is
>>a way to perform partial validation of XML documents? I mean, I have
>>only seen a normalizeDocument() method on the Document class, but what I
>>would like to be able to do is to validate parts of a document below the
>>document root, too. Is there a way to achieve that? Or is this feature
>>perhaps planned for a future release?
>
>
> See email below.
Thanks for that info!
Have a nice day,
--
Christian Schuhegger
http://galileo.spaceports.com/~cschuheg
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
Re: accessing schema validated values
Posted by Elena Litani <el...@ca.ibm.com>.
Hi Christian,
Thank you for your reply.
Christian Schuhegger wrote:
> Your proposal to expose the validated values in the ItemPSVI classes
> sounds like a very good idea to me. Perhaps it is possible to extend the
> internal data representation classes like the XDecimal to return actual
> Java object representations of the basic types in parallel to extend the
> ItemPSVI interfaces?
I believe the ItemPSVI interface should have only one method that
returns an Object representing the actual value. Given that, you will
need to have bunch of instanceof checks in your code to be able to cast
to the internal Xerces representation, i.e. XDecimal, and then get a
Java decimal (a method could be defined on XDecimal). Are you fine with
this solution?
There are couple of alternative solutions, so if you want to discuss it
lets do it on the xerces-j-dev mailing list.
> While I am just writing this e-mail I would also like to ask if there is
> a way to perform partial validation of XML documents? I mean, I have
> only seen a normalizeDocument() method on the Document class, but what I
> would like to be able to do is to validate parts of a document below the
> document root, too. Is there a way to achieve that? Or is this feature
> perhaps planned for a future release?
See email below.
Thank you,
--
Elena Litani / IBM Toronto
-------- Original Message --------
Subject: Re: How to validate an element rather than the whole xml
document
Date: Thu, 25 Sep 2003 11:40:46 -0400
From: Elena Litani <el...@ca.ibm.com>
Reply-To: xerces-j-user@xml.apache.org
To: xerces-j-user@xml.apache.org
References: <01...@11089026301>
> I need to validate an element aganist schema rather than the
> whole document.
Currently, it is not possible to revalidate a singe element within the
DOM tree.
The best way of achieving what you want is using DOM Level 3
normalizeDocument that allows to revalidate a document in memory [1].
You can setup the schema on the <key> element using xsi:schemaLocation
attributes and register your own error handler that will ignore errors
for <SOAPENV:Envelope>, <SOAPBODY:Body> elements (the validator will
complain that declaration for those is not found).
If you really want to revalidate a single node.. you can create a new
document, use adoptNode to move a single element you want to revalidate
to a new document, use DOM L3 normalizeDocument on the new document to
revalidate just that single node. Then, if needed, you can use adoptNode
again to move back the element to the original document.
[1] http://xml.apache.org/xerces2-j/faq-dom.html#faq-7
Hope it helps,
--
Elena Litani / IBM Toronto
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org