You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by brutocao <Ja...@jpl.nasa.gov> on 2005/02/01 21:49:17 UTC
Getting PSVI from DOM tree
Hello,
I have been looking through the xerces mail archives, and still cannot seem
to get my code to work. My basic question is: if I am walking the DOM tree
using xerces-c++, how can I get at the PSVI information from a DOMNode
pointer (which I call curNode in the code samples below)? I found this code
to work:
const XMLCh *typeName;
DOMPSVITypeInfo *psviType;
psviType = (DOMPSVITypeInfo*)
curNode->getInterface(XMLUni::fgXercescInterfacePSVITypeInfo);
if (!psviType) return DMT_NONE;
typeName =
psviType->getStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Name);
if (!typeName) return DMT_NONE;
if (!strcmp(S(typeName), "string")) return DMT_STRING;
if (!strcmp(S(typeName), "boolean")) return DMT_BOOL;
if (!strcmp(S(typeName), "integer") ||
!strcmp(S(typeName), "short") ||
!strcmp(S(typeName), "long")) return DMT_INT;
if (!strcmp(S(typeName), "double") ||
!strcmp(S(typeName), "float")) return DMT_DOUBLE;
which is great, but it only handles finding the type of an element when the
type is an attribute on that element. But I want to find out everything
about an element, including when it is a complex type or a simple type with
restrictions. For instance, if the schema says:
<xs:element
name="Years">
<xs:simpleType>
<xs:restriction
base="xs:integer">
<xs:minInclusive
value="1900"/>
<xs:maxInclusive
value="3000"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
how can I find out the minInclusive and maxInclusive values straight from
the DOMNode pointer to the "Years" element? I have tried code such as:
PSVIElement *psviElem = (PSVIElement *) curNode;
XSTypeDefinition *def = psviElem->getTypeDefinition();
cout<<psviElem->getValidity()<<endl;
enum XSTypeDefinition::TYPE_CATEGORY cat = def->getTypeCategory();
cout<<cat<<endl;
if (cat == XSTypeDefinition::COMPLEX_TYPE)
{
cout<<"yes"<<endl;
}
but this code produces garbage in the cout's.
Can you help me?
Thanks much,
Jim
Re: Getting PSVI from DOM tree
Posted by brutocao <Ja...@jpl.nasa.gov>.
Alberto,
Thanks much. This is very helpful. I used this exact code you have
provided, with curNode pointing to the following element in the DOM tree:
<xs:element name="Solar_DisAU">
<xs:simpleType>
<xs:restriction base="xs:double">
<xs:minInclusive value="0.1"/>
<xs:maxInclusive value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
It correctly determined that it was a simple type. But for some reason,
when I called:
DatatypeValidator*
pSimpleType=pSchema->getDatatypeRegistry()->getDatatypeValidator(typeName);
pSimpleType was set to null. Any idea why?
Regards,
Jim
At 12:35 AM 2/2/2005, you wrote:
>Hi Jim,
>
>At 14.53 01/02/2005 -0800, brutocao wrote:
>>Alberto,
>>
>>Thanks, that was very helpful. I cut and pasted in the SEnumVal code and
>>I am now traversing the schema info. Now I want to only consider my node
>>of interest, which you have let me know is found with getGrammar(uri).
>>
>>curNode is the pointer to the DOMNode of interest. In trying to find the
>>namespace URI for this node, I tried this and it failed:
>>
>> SchemaGrammar *gram = (SchemaGrammar *) parser->
>> getGrammar(((PSVIElement *)
>> curNode)->getElementDeclaration()->getNamespace());
>>
>>What would be the correct syntax?
>
>As a suggestion for the future, every time you need to write a cast on an
>object, there is something wrong....you cannot take a DOMNode and treat it
>as it were a PSVIElement; at best, you will get unexpected results, but
>most likely your application will crash.
>
>Let's start from the code you originally posted:
>
> const XMLCh *typeName;
> DOMPSVITypeInfo *psviType;
>
> psviType = (DOMPSVITypeInfo*)
>
>curNode->getInterface(XMLUni::fgXercescInterfacePSVITypeInfo);
> if (!psviType) return DMT_NONE;
>
> typeName =
> psviType->getStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Name);
> if (!typeName) return DMT_NONE;
>
>Now let's get the URI for the type:
>
> const XMLCh
> *typeURI=psviType->getStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Namespace);
>
>Then ask for which type (simple vs complex) we have to search:
>
> XSTypeDefinition::TYPE_CATEGORY typeType=
> (XSTypeDefinition::TYPE_CATEGORY)psviType->getNumericProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Type);
>
>Finally, ask the parser for the type definition:
>
> Grammar* pGrammar=parser.getGrammar(typeURI);
> if(pGrammar &&
> pGrammar->getGrammarType()==Grammar::SchemaGrammarType)
> {
> SchemaGrammar* pSchema=(SchemaGrammar*)pGrammar;
> if(typeType==XSTypeDefinition::COMPLEX_TYPE)
> {
> XMLBuffer typeKey(1023);
> typeKey.set(typeURI);
> typeKey.append(chComma);
> typeKey.append(typeName);
> ComplexTypeInfo*
> pComplexType=pSchema->getComplexTypeRegistry()->get(typeKey.getRawBuffer());
> }
> else
> {
> DatatypeValidator*
> pSimpleType=pSchema->getDatatypeRegistry()->getDatatypeValidator(typeName);
> }
> }
>
>
>Alberto
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: Getting PSVI from DOM tree
Posted by Alberto Massari <am...@datadirect.com>.
Hi Jim,
At 14.53 01/02/2005 -0800, brutocao wrote:
>Alberto,
>
>Thanks, that was very helpful. I cut and pasted in the SEnumVal code and I
>am now traversing the schema info. Now I want to only consider my node of
>interest, which you have let me know is found with getGrammar(uri).
>
>curNode is the pointer to the DOMNode of interest. In trying to find the
>namespace URI for this node, I tried this and it failed:
>
> SchemaGrammar *gram = (SchemaGrammar *) parser->
> getGrammar(((PSVIElement *)
> curNode)->getElementDeclaration()->getNamespace());
>
>What would be the correct syntax?
As a suggestion for the future, every time you need to write a cast on an
object, there is something wrong....you cannot take a DOMNode and treat it
as it were a PSVIElement; at best, you will get unexpected results, but
most likely your application will crash.
Let's start from the code you originally posted:
const XMLCh *typeName;
DOMPSVITypeInfo *psviType;
psviType = (DOMPSVITypeInfo*)
curNode->getInterface(XMLUni::fgXercescInterfacePSVITypeInfo);
if (!psviType) return DMT_NONE;
typeName =
psviType->getStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Name);
if (!typeName) return DMT_NONE;
Now let's get the URI for the type:
const XMLCh
*typeURI=psviType->getStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Namespace);
Then ask for which type (simple vs complex) we have to search:
XSTypeDefinition::TYPE_CATEGORY typeType=
(XSTypeDefinition::TYPE_CATEGORY)psviType->getNumericProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Type);
Finally, ask the parser for the type definition:
Grammar* pGrammar=parser.getGrammar(typeURI);
if(pGrammar && pGrammar->getGrammarType()==Grammar::SchemaGrammarType)
{
SchemaGrammar* pSchema=(SchemaGrammar*)pGrammar;
if(typeType==XSTypeDefinition::COMPLEX_TYPE)
{
XMLBuffer typeKey(1023);
typeKey.set(typeURI);
typeKey.append(chComma);
typeKey.append(typeName);
ComplexTypeInfo*
pComplexType=pSchema->getComplexTypeRegistry()->get(typeKey.getRawBuffer());
}
else
{
DatatypeValidator*
pSimpleType=pSchema->getDatatypeRegistry()->getDatatypeValidator(typeName);
}
}
Alberto
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: Getting PSVI from DOM tree
Posted by brutocao <Ja...@jpl.nasa.gov>.
Alberto,
Thanks, that was very helpful. I cut and pasted in the SEnumVal code and I
am now traversing the schema info. Now I want to only consider my node of
interest, which you have let me know is found with getGrammar(uri).
curNode is the pointer to the DOMNode of interest. In trying to find the
namespace URI for this node, I tried this and it failed:
SchemaGrammar *gram = (SchemaGrammar *) parser->
getGrammar(((PSVIElement *)
curNode)->getElementDeclaration()->getNamespace());
What would be the correct syntax?
Thanks,
Jim
At 01:22 PM 2/1/2005, you wrote:
>Hi Jim,
>
>At 13.13 01/02/2005 -0800, brutocao wrote:
>>Thanks Alberto,
>>
>>I couldn't seem to find where the GrammarResolver object is located. It
>>was not in the DOMNode object, nor in the DOMPSVITypeInfo object that I
>>got from the DOMNode object. How do I get at it?
>
>You can get it from the parser object that you used to build the DOM tree.
>As an example, look at the SEnumVal sample; but, instead of asking for the
>grammar for the root element (using getRootGrammar), you should ask for
>the grammar of the type/element you are looking for (using getGrammar(uri))
>
>Alberto
>
>
>>Thanks again,
>>
>>Jim
>>
>>At 12:57 PM 2/1/2005, you wrote:
>>>Hi Jim,
>>>
>>>At 12.49 01/02/2005 -0800, brutocao wrote:
>>>>Hello,
>>>>
>>>>I have been looking through the xerces mail archives, and still cannot
>>>>seem to get my code to work. My basic question is: if I am walking the
>>>>DOM tree using xerces-c++, how can I get at the PSVI information from a
>>>>DOMNode pointer (which I call curNode in the code samples below)? I
>>>>found this code to work:
>>>>[...]
>>>
>>>This method returns you the name of the type, whether is a simple or
>>>complex type and so on; at that point you can look at the
>>>GrammarResolver object, retrieve the object for that type and walk its
>>>inheritance chain.
>>>Or you can install your own PSVIHandler object into the parser and
>>>navigate the PSVIElement object that is provided (for this method, have
>>>a look at the PSVIWriter sample).
>>>
>>>Alberto
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
>>>For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
>>For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: Getting PSVI from DOM tree
Posted by Alberto Massari <am...@datadirect.com>.
Hi Jim,
At 13.13 01/02/2005 -0800, brutocao wrote:
>Thanks Alberto,
>
>I couldn't seem to find where the GrammarResolver object is located. It
>was not in the DOMNode object, nor in the DOMPSVITypeInfo object that I
>got from the DOMNode object. How do I get at it?
You can get it from the parser object that you used to build the DOM tree.
As an example, look at the SEnumVal sample; but, instead of asking for the
grammar for the root element (using getRootGrammar), you should ask for the
grammar of the type/element you are looking for (using getGrammar(uri))
Alberto
>Thanks again,
>
>Jim
>
>At 12:57 PM 2/1/2005, you wrote:
>>Hi Jim,
>>
>>At 12.49 01/02/2005 -0800, brutocao wrote:
>>>Hello,
>>>
>>>I have been looking through the xerces mail archives, and still cannot
>>>seem to get my code to work. My basic question is: if I am walking the
>>>DOM tree using xerces-c++, how can I get at the PSVI information from a
>>>DOMNode pointer (which I call curNode in the code samples below)? I
>>>found this code to work:
>>>[...]
>>
>>This method returns you the name of the type, whether is a simple or
>>complex type and so on; at that point you can look at the GrammarResolver
>>object, retrieve the object for that type and walk its inheritance chain.
>>Or you can install your own PSVIHandler object into the parser and
>>navigate the PSVIElement object that is provided (for this method, have a
>>look at the PSVIWriter sample).
>>
>>Alberto
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
>>For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: Getting PSVI from DOM tree
Posted by brutocao <Ja...@jpl.nasa.gov>.
Thanks Alberto,
I couldn't seem to find where the GrammarResolver object is located. It was
not in the DOMNode object, nor in the DOMPSVITypeInfo object that I got
from the DOMNode object. How do I get at it?
Thanks again,
Jim
At 12:57 PM 2/1/2005, you wrote:
>Hi Jim,
>
>At 12.49 01/02/2005 -0800, brutocao wrote:
>>Hello,
>>
>>I have been looking through the xerces mail archives, and still cannot
>>seem to get my code to work. My basic question is: if I am walking the
>>DOM tree using xerces-c++, how can I get at the PSVI information from a
>>DOMNode pointer (which I call curNode in the code samples below)? I found
>>this code to work:
>>[...]
>
>This method returns you the name of the type, whether is a simple or
>complex type and so on; at that point you can look at the GrammarResolver
>object, retrieve the object for that type and walk its inheritance chain.
>Or you can install your own PSVIHandler object into the parser and
>navigate the PSVIElement object that is provided (for this method, have a
>look at the PSVIWriter sample).
>
>Alberto
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: Getting PSVI from DOM tree
Posted by Alberto Massari <am...@datadirect.com>.
Hi Jim,
At 12.49 01/02/2005 -0800, brutocao wrote:
>Hello,
>
>I have been looking through the xerces mail archives, and still cannot
>seem to get my code to work. My basic question is: if I am walking the DOM
>tree using xerces-c++, how can I get at the PSVI information from a
>DOMNode pointer (which I call curNode in the code samples below)? I found
>this code to work:
>[...]
This method returns you the name of the type, whether is a simple or
complex type and so on; at that point you can look at the GrammarResolver
object, retrieve the object for that type and walk its inheritance chain.
Or you can install your own PSVIHandler object into the parser and navigate
the PSVIElement object that is provided (for this method, have a look at
the PSVIWriter sample).
Alberto
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org