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 David Cao <go...@gmail.com> on 2009/06/22 03:03:49 UTC

If an element is a simple or array element

Hi there,
I need to be able to parse (either via DOM or SAX) an XML with namespace
spread out in several schema; this means the final type could reside in an
embedded schema a couple level deeper. I need to tell if an element is
defined as a simple type or as an array type.

I took the sample jaxp.TypeInfoWriter (because I also need access
to org.w3c.dom.TypeInfo); then to add a org.apache.xerces.xs.PSVIProvider to
the handler,

   private PSVIProvider fPSVIProvider;

and set it this way,

   org.apache.xerces.parsers.SAXParser saxParser = new
org.apache.xerces.parsers.SAXParser();
   fPSVIProvider = (PSVIProvider)saxParser;

However, in the startElement( ... ) method, I did this,

   ElementPSVI elemPSVI = fPSVIProvider.getElementPSVI();

unfortunately, elemPSVI is always null no matter how I configure the schema
validation options.

So, is my approach workable? if yes, what I did wrong. Or is there better
approach?

------------------------------

Also, I tried out-of-box simpletype.DatatypeInterfaceUsage sample on the
provided personal.xsd and personal-schema.xml; I found the same result. But
I found the underlying parsers are different between the two samples. One
uses,
   org.apache.xerces.jaxp.SAXParserImpl, which inherits
javax.xml.parsers.SAXParser
the other uses,
   org.apache.xerces.parsers.SAXParser

I found although they have the same simple name, they don't overlap at all.
So how to choose which to use one or the other?

Much appreciated,
David

Re: If an element is a simple or array element

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Mukul Gandhi <ga...@gmail.com> wrote on 06/23/2009 11:30:31 PM:

> Hi David,
>
> On Wed, Jun 24, 2009 at 6:35 AM, govelogo<go...@gmail.com> wrote:
> > But I got this error,
> > error: Parse error occurred -
> > com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl
> > java.lang.ClassCastException:
> > com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl
> >         at TypeInfoWriter.main(TypeInfoWriter.java:558)
>
> It seems, you have hit a classpath issue. Your application seems to be
> using the JAXP implementation available in Sun JDK. You may try
> setting a system property to use Xerces-J JAXP SchemaFactory.
> Something like below:
>
> System.setProperty("javax.xml.validation.SchemaFactory:http://www.
>
w3.org/2001/XMLSchema","org.apache.xerces.jaxp.validation.XMLSchemaFactory");

>
> Michael, might be able to provide a more correct answer :)

There's a bug [1] in some JDK versions which would cause this. You can also
resolve it by putting the xml-apis.jar from Xerces in the JDK's endorsed
directory.

> --
> Regards,
> Mukul Gandhi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org

[1] http://markmail.org/message/rvlroblxyza3xt3v

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Re: If an element is a simple or array element

Posted by govelogo <go...@gmail.com>.
Hi Mukul and Michael,
Just out of a quick try, it seems made a difference and should be able to
get me what I want.

thanks a lot,
-david

On Wed, Jun 24, 2009 at 12:30 AM, Mukul Gandhi <ga...@gmail.com>wrote:

> Hi David,
>
> On Wed, Jun 24, 2009 at 6:35 AM, govelogo<go...@gmail.com> wrote:
> > But I got this error,
> > error: Parse error occurred -
> > com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl
> > java.lang.ClassCastException:
> > com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl
> >         at TypeInfoWriter.main(TypeInfoWriter.java:558)
>
> It seems, you have hit a classpath issue. Your application seems to be
> using the JAXP implementation available in Sun JDK. You may try
> setting a system property to use Xerces-J JAXP SchemaFactory.
> Something like below:
>
> System.setProperty("javax.xml.validation.SchemaFactory:
> http://www.w3.org/2001/XMLSchema
> ","org.apache.xerces.jaxp.validation.XMLSchemaFactory");
>
> Michael, might be able to provide a more correct answer :)
>
>
> --
> Regards,
> Mukul Gandhi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
>

Re: If an element is a simple or array element

Posted by Mukul Gandhi <ga...@gmail.com>.
Hi David,

On Wed, Jun 24, 2009 at 6:35 AM, govelogo<go...@gmail.com> wrote:
> But I got this error,
> error: Parse error occurred -
> com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl
> java.lang.ClassCastException:
> com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl
>         at TypeInfoWriter.main(TypeInfoWriter.java:558)

It seems, you have hit a classpath issue. Your application seems to be
using the JAXP implementation available in Sun JDK. You may try
setting a system property to use Xerces-J JAXP SchemaFactory.
Something like below:

System.setProperty("javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema","org.apache.xerces.jaxp.validation.XMLSchemaFactory");

Michael, might be able to provide a more correct answer :)


-- 
Regards,
Mukul Gandhi

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: If an element is a simple or array element

Posted by govelogo <go...@gmail.com>.
Hi Michael,
In the "jaxp.TypeInfoWriter" sample main() method, after the creation of
"ValidatorHandler" line,

   ValidatorHandler validator = schema.newValidatorHandler();

I added this line,

   writer.setPSVIProvider((org.apache.xerces.xs.PSVIProvider)validator);

But I got this error,

error: Parse error occurred -
com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl
java.lang.ClassCastException:
com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl
        at TypeInfoWriter.main(TypeInfoWriter.java:558)

In the FAQ link you sent, it says "javax.xml.validation.Validator and
javax.xml.validation.ValidatorHandler also implement the
org.apache.xerces.xs.PSVIProvider interface." But, from Java api doc, I
could not tell the interface is implemented.

Did I get the wrong ValidatorHandler implementation class? but that's OOB
sample code.

thanks a lot,
-david


On Tue, Jun 23, 2009 at 9:59 AM, Michael Glavassevich
<mr...@ca.ibm.com>wrote:

> govelogo <go...@gmail.com> wrote on 06/23/2009 07:26:55 AM:
>
>
> > Do you mean I can cast "javax.xml.validation.ValidatorHandler" into
> > a "org.apache.xerces.xs.PSVIProvider"? I can not see how to do that
> > from java their doc.
>
>
> Have you tried this? It should work. See "How do I access PSVI via the
> JAXP 1.3 Validation API?":
> http://xerces.apache.org/xerces2-j/faq-xs.html#faq-8.
>
> Thanks.
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
>

Re: If an element is a simple or array element

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
govelogo <go...@gmail.com> wrote on 06/23/2009 07:26:55 AM:

> Do you mean I can cast "javax.xml.validation.ValidatorHandler" into
> a "org.apache.xerces.xs.PSVIProvider"? I can not see how to do that
> from java their doc.

Have you tried this? It should work. See "How do I access PSVI via the JAXP
1.3 Validation API?":
http://xerces.apache.org/xerces2-j/faq-xs.html#faq-8..

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Re: If an element is a simple or array element

Posted by govelogo <go...@gmail.com>.
Hi Mukul,
Sorry. I mean "array type" is a complex type with a sequence of elements.

ElementPSVI is the object I figured that could get me the information.
However, I have two issues; one is that I could not have
"simpletype.DatatypeInterfaceUsage"
working for some reason. The 2nd is I don't know how to apply "PSVIProvider"
into your "jaxp.TypeInfoWriter" sample.

Many thanks,
David


On Tue, Jun 23, 2009 at 8:40 AM, Mukul Gandhi <ga...@gmail.com>wrote:

> On Tue, Jun 23, 2009 at 4:56 PM, govelogo<go...@gmail.com> wrote:
> > My ultimate goal is to be able to tell if a schema type associated to an
> > element is a simple type or an array type while parsing an xml.
>
> I don't understand, what do you mean by "array type". We only have
> simple type or a complex type.
>
> Once you have the ElementPSVI object for the element, you can access
> the element type information using the available APIs.
>
>
> --
> Regards,
> Mukul Gandhi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
>

Re: If an element is a simple or array element

Posted by Mukul Gandhi <ga...@gmail.com>.
On Tue, Jun 23, 2009 at 4:56 PM, govelogo<go...@gmail.com> wrote:
> My ultimate goal is to be able to tell if a schema type associated to an
> element is a simple type or an array type while parsing an xml.

I don't understand, what do you mean by "array type". We only have
simple type or a complex type.

Once you have the ElementPSVI object for the element, you can access
the element type information using the available APIs.


-- 
Regards,
Mukul Gandhi

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: If an element is a simple or array element

Posted by govelogo <go...@gmail.com>.
Hi Michael,
My ultimate goal is to be able to tell if a schema type associated to an
element is a simple type or an array type while parsing an xml. As to how to
implement it, I am not sure. I was just trying.

Do you mean I can cast "javax.xml.validation.ValidatorHandler" into a
"org.apache.xerces.xs.PSVIProvider"? I can not see how to do that from java
their doc.

Also, what's the real difference between your sample "jaxp.TypeInfoWriter"
and "simpletype.DatatypeInterfaceUsage"? They both use JAXP package, do
they?

I can not have "simpletype.DatatypeInterfaceUsage" working on your sample
"ersonal.xsd" and "personal-schema.xml".

I guess I am still not clear with some of the xerces concepts. I hope to get
through this would help me understand.

Thanks a lot for your help.
-david


On Mon, Jun 22, 2009 at 11:59 PM, Michael Glavassevich
<mr...@ca.ibm.com>wrote:

> Hi David,
>
> I'm not sure I understand what you're doing. The jaxp.TypeInfoWriter sample
> shows how to get type information from a JAXP validator. If you're using the
> JAXP Validation API the PSVIProvider is the ValidatorHandler not the SAX
> parser.
>
> Thanks.
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> David Cao <go...@gmail.com> wrote on 06/21/2009 09:03:49 PM:
>
> > Hi there,
>
> >
> > I need to be able to parse (either via DOM or SAX) an XML with
> > namespace spread out in several schema; this means the final type
> > could reside in an embedded schema a couple level deeper. I need to
> > tell if an element is defined as a simple type or as an array type.
> >
> > I took the sample jaxp.TypeInfoWriter (because I also need access
> > to org.w3c.dom.TypeInfo); then to add a org.apache.xerces.xs.
> > PSVIProvider to the handler,
> >
> >    private PSVIProvider fPSVIProvider;
> >
> > and set it this way,
> >
> >    org.apache.xerces.parsers.SAXParser saxParser = new org.apache.
> > xerces.parsers.SAXParser();
> >    fPSVIProvider = (PSVIProvider)saxParser;
> >
> > However, in the startElement( ... ) method, I did this,
> >
> >    ElementPSVI elemPSVI = fPSVIProvider.getElementPSVI();
> >
> > unfortunately, elemPSVI is always null no matter how I configure the
> > schema validation options.
> >
> > So, is my approach workable? if yes, what I did wrong. Or is there
> > better approach?
> >
> > ------------------------------
> >
> > Also, I tried out-of-box simpletype.DatatypeInterfaceUsage sample on
> > the provided personal.xsd and personal-schema.xml; I found the same
> > result. But I found the underlying parsers are different between the
> > two samples. One uses,
> >    org.apache.xerces.jaxp.SAXParserImpl, which inherits javax.xml.
> > parsers.SAXParser
> > the other uses,
> >    org.apache.xerces.parsers.SAXParser
> >
> > I found although they have the same simple name, they don't overlap
> > at all. So how to choose which to use one or the other?
> >
> > Much appreciated,
> > David
>
>

Re: If an element is a simple or array element

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi David,

I'm not sure I understand what you're doing. The jaxp.TypeInfoWriter sample
shows how to get type information from a JAXP validator. If you're using
the JAXP Validation API the PSVIProvider is the ValidatorHandler not the
SAX parser.

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

David Cao <go...@gmail.com> wrote on 06/21/2009 09:03:49 PM:

> Hi there,
>
> I need to be able to parse (either via DOM or SAX) an XML with
> namespace spread out in several schema; this means the final type
> could reside in an embedded schema a couple level deeper. I need to
> tell if an element is defined as a simple type or as an array type.
>
> I took the sample jaxp.TypeInfoWriter (because I also need access
> to org.w3c.dom.TypeInfo); then to add a org.apache.xerces.xs.
> PSVIProvider to the handler,
>
>    private PSVIProvider fPSVIProvider;
>
> and set it this way,
>
>    org.apache.xerces.parsers.SAXParser saxParser = new org.apache.
> xerces.parsers.SAXParser();
>    fPSVIProvider = (PSVIProvider)saxParser;
>
> However, in the startElement( ... ) method, I did this,
>
>    ElementPSVI elemPSVI = fPSVIProvider.getElementPSVI();
>
> unfortunately, elemPSVI is always null no matter how I configure the
> schema validation options.
>
> So, is my approach workable? if yes, what I did wrong. Or is there
> better approach?
>
> ------------------------------
>
> Also, I tried out-of-box simpletype.DatatypeInterfaceUsage sample on
> the provided personal.xsd and personal-schema.xml; I found the same
> result. But I found the underlying parsers are different between the
> two samples. One uses,
>    org.apache.xerces.jaxp.SAXParserImpl, which inherits javax.xml.
> parsers.SAXParser
> the other uses,
>    org.apache.xerces.parsers.SAXParser
>
> I found although they have the same simple name, they don't overlap
> at all. So how to choose which to use one or the other?
>
> Much appreciated,
> David