You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Timothy Strimple <ts...@collectivedata.com> on 2007/01/22 19:13:42 UTC

Retrieve list of valid children based on element name.

I'm trying to setup a system that will allow me to dynamically build xml 
documents based on a schema. I've successfully implemented PSVI thinking 
that would be all I needed to build the list I wanted, however it only 
seems to build a list of children that are actually in the xml, not what 
is defined within the schema. For example, in the case of an optional 
attribute, it doesn't show up unless the xml document contains it, even 
though it's allowed via the stylesheet. I basically just need a list of 
valid elements and attributes for a particular element. Is there a way 
to build this list using xerces?

Thanks,
Timothy Strimple

Re: Retrieve list of valid children based on element name.

Posted by Alberto Massari <am...@datadirect.com>.
At 08.48 24/01/2007 -0600, Timothy Strimple wrote:
>Alberto Massari wrote:
>>Timothy,
>>XSTypeDefinition is just the base class; depending on the value 
>>returned by getTypeCategory() you have to cast it to either a 
>>XSComplexTypeDefinition or XSSimpleTypeDefinition, where you will 
>>find the rest of the informations.
>>
>>Alberto
>Ah! Thank you very much! So getAttributeUses() for the attributes 
>and getParticle() for the content information? Is documentation on 
>this other then whats listed in the Xerces documentation? It looks 
>like I can call getElementTerm() to retrieve a single element from 
>the particle, or getModelGroupTerm() if there is a set of elements. 
>Also, is there a resource for explaining the terms used in the PSVI? 
>Are Model Groups and Wildcards related to XML Schema or specifically 
>to the PSVI. I'm hoping to find a better way to learn more about 
>this type of schema work without having to pester the list with a 
>lot of questions.

Hi Timothy,
the naming comes from the XMLSchema lingo; infact, the entire data 
structure is replicating how the schema was written. As for the 
documentation, the only other part you can read is the sample SCMPrint.

Alberto 


Re: Retrieve list of valid children based on element name.

Posted by Timothy Strimple <ts...@collectivedata.com>.
Alberto Massari wrote:
> Timothy,
> XSTypeDefinition is just the base class; depending on the value 
> returned by getTypeCategory() you have to cast it to either a 
> XSComplexTypeDefinition or XSSimpleTypeDefinition, where you will find 
> the rest of the informations.
>
> Alberto
Ah! Thank you very much! So getAttributeUses() for the attributes and 
getParticle() for the content information? Is documentation on this 
other then whats listed in the Xerces documentation? It looks like I can 
call getElementTerm() to retrieve a single element from the particle, or 
getModelGroupTerm() if there is a set of elements. Also, is there a 
resource for explaining the terms used in the PSVI? Are Model Groups and 
Wildcards related to XML Schema or specifically to the PSVI. I'm hoping 
to find a better way to learn more about this type of schema work 
without having to pester the list with a lot of questions.

Thanks,
  Tim.

Re: Retrieve list of valid children based on element name.

Posted by Alberto Massari <am...@datadirect.com>.
Timothy,
XSTypeDefinition is just the base class; depending on the value 
returned by getTypeCategory() you have to cast it to either a 
XSComplexTypeDefinition or XSSimpleTypeDefinition, where you will 
find the rest of the informations.

Alberto

At 08.29 24/01/2007 -0600, Timothy Strimple wrote:
>Boris Kolpackov wrote:
>>Hi Timothy,
>>
>>I am somewhat confused by your description, but if you managed to get
>>a, say, PSVIElement for an element in your instance, then you can get
>>to XSTypeDefinition which describes the type that was used to validate
>>this element. From XSTypeDefinition you should be able to get the
>>complete content model of a type, including elements and attributes.
>>
>>
>>hth,
>>-boris
>>
>>
>>
>Boris,
>
>I must be missing something then. From what I can tell, the 
>XSTypeDefinition only provides functions for retrieving the name and 
>namespace of the type. I'm looking at the documentation here, 
>http://xml.apache.org/xerces-c/apiDocs/classXSTypeDefinition.html 
>which exposes the following functions.
>
>const XMLCh* getName()
>const XMLCh* getNamespace()
>XSNamespaceItem* getNamespaceItem()
>
>TYPE_CATEGORY getTypeCategory()
>XSTypeDefinition* getBaseType()
>bool isFinal(short toTest)
>short getFinal()
>bool getAnonymous()
>bool derivedFromType(const XSTypeDefinition *const ancestorType)
>bool derivedFrom(const XMLCh *typeNamespace, const XMLCh *name)
>
>None of which seem to be able to do what I need. Could you provide 
>some pseudo code for using XXTypeDefinition to get the valid 
>children / attributes of the element?
>
>Thanks,
>  Tim


Re: Retrieve list of valid children based on element name.

Posted by Timothy Strimple <ts...@collectivedata.com>.
Boris Kolpackov wrote:
> Hi Timothy,
>
> I am somewhat confused by your description, but if you managed to get
> a, say, PSVIElement for an element in your instance, then you can get
> to XSTypeDefinition which describes the type that was used to validate
> this element. From XSTypeDefinition you should be able to get the
> complete content model of a type, including elements and attributes.
>
>
> hth,
> -boris
>
>
>   
Boris,

I must be missing something then. From what I can tell, the 
XSTypeDefinition only provides functions for retrieving the name and 
namespace of the type. I'm looking at the documentation here, 
http://xml.apache.org/xerces-c/apiDocs/classXSTypeDefinition.html which 
exposes the following functions.

const XMLCh* getName()
const XMLCh* getNamespace()
XSNamespaceItem* getNamespaceItem()

TYPE_CATEGORY getTypeCategory()
XSTypeDefinition* getBaseType()
bool isFinal(short toTest)
short getFinal()
bool getAnonymous()
bool derivedFromType(const XSTypeDefinition *const ancestorType)
bool derivedFrom(const XMLCh *typeNamespace, const XMLCh *name)

None of which seem to be able to do what I need. Could you provide some 
pseudo code for using XXTypeDefinition to get the valid children / 
attributes of the element?

Thanks,
  Tim

Re: Retrieve list of valid children based on element name.

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi Timothy,

Timothy Strimple <ts...@collectivedata.com> writes:

> I'm trying to setup a system that will allow me to dynamically build xml
> documents based on a schema. I've successfully implemented PSVI thinking
> that would be all I needed to build the list I wanted, however it only
> seems to build a list of children that are actually in the xml, not what
> is defined within the schema. For example, in the case of an optional
> attribute, it doesn't show up unless the xml document contains it, even
> though it's allowed via the stylesheet. I basically just need a list of
> valid elements and attributes for a particular element. Is there a way
> to build this list using xerces?

I am somewhat confused by your description, but if you managed to get
a, say, PSVIElement for an element in your instance, then you can get
to XSTypeDefinition which describes the type that was used to validate
this element. From XSTypeDefinition you should be able to get the
complete content model of a type, including elements and attributes.


hth,
-boris


-- 
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding