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 "a.desentenac" <a....@laposte.net> on 2005/10/04 17:20:36 UTC

Getting type info of a DOMNode

I parse an XML File using a DOMBuilderImpl and use a XML
Schema to validate it.
Then i would like to get, for any given DOMNode, the
information of the corresponding type.

For now i've tried something like that :

const XMLCh *typeName;

DOMPSVITypeInfo *typeInfo = (DOMPSVITypeInfo*)
domNode->getInterface(XMLUni::fgXercescInterfacePSVITypeInfo);
if (typeInfo)
{
	typeName =
typeInfo->getStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Name);
	if (typeName)
	{
		const XMLCh *typeURI =
typeInfo->getStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Namespace);

		XSTypeDefinition::TYPE_CATEGORY typeType =
(XSTypeDefinition::TYPE_CATEGORY)typeInfo->getNumericProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Type);

		Grammar* pGrammar = parser->getGrammar(typeURI);
		if(pGrammar &&
pGrammar->getGrammarType()==Grammar::SchemaGrammarType)
		{
			SchemaGrammar* pSchemaGrammar = (SchemaGrammar*)pGrammar;
			if(typeType==XSTypeDefinition::COMPLEX_TYPE)
			{
				XMLBuffer typeKey(1023);
				typeKey.set(typeURI);
				typeKey.append(chComma);
				typeKey.append(typeName);
				ComplexTypeInfo* pComplexType =
pSchemaGrammar->getComplexTypeRegistry()->get(typeKey.getRawBuffer());
				cout << "type : " <<
XMLString::transcode(pComplexType->getTypeName()) << endl;
			}
			else
			{
				DatatypeValidator* pSimpleType =
pSchemaGrammar->getDatatypeRegistry()->getDatatypeValidator(typeName);
				if(pSimpleType)
				{
					switch( pSimpleType->getType() )
					{
					case DatatypeValidator::String:         cout << "string";
     break;
					case DatatypeValidator::AnyURI:         cout << "AnyURI";
     break;
					[snip]
					}
					cout << endl;
				}
			}
		}
	}
}

so it gives me the names of the types but i don't know how to
get more info (like the values of an enumeration), i've looked
at the SCMPrint example but i can't find a way to get from
what i have to a XSTypeDefinition.
Any help is welcome :)

By the way, as a minor problem, i have the same problem as
stated there with my code :
http://www.mail-archive.com/xerces-c-dev@xml.apache.org/msg14794.html
The DatatypeValidator is null on anonymous simple types, and i
don't know why either.

Regards,
Adrien de Sentenac

Accédez au courrier électronique de La Poste : www.laposte.net ; 
3615 LAPOSTENET (0,34€/mn) ; tél : 08 92 68 13 50 (0,34€/mn)




Re: Getting type info of a DOMNode

Posted by Alberto Massari <am...@datadirect.com>.
Hi Adrien,

At 17.20 04/10/2005 +0200, a\.desentenac wrote:
>I parse an XML File using a DOMBuilderImpl and 
>use a XML Schema to validate it.
>Then i would like to get, for any given DOMNode, 
>the information of the corresponding type.
>
>[..]
>
>so it gives me the names of the types but i don't know how to
>get more info (like the values of an enumeration), i've looked
>at the SCMPrint example but i can't find a way to get from
>what i have to a XSTypeDefinition.
>Any help is welcome :)

You can get the enumeration from the 
DatatypeValidator object by invoking getEnumString().
If you prefer navigating the XSxxxx type 
hierarchy, you should first build the XSModel 
object from the grammar by calling 
parser->getGrammarResolver()->getXSModel(). After 
that, you can get the element declaration by 
using XSModel::getElementDeclaration(typeName, typeURI).

Hope this helps,
Alberto


>By the way, as a minor problem, i have the same problem as
>stated there with my code :
>http://www.mail-archive.com/xerces-c-dev@xml.apache.org/msg14794.html
>The DatatypeValidator is null on anonymous simple types, and i
>don't know why either.
>
>Regards,
>Adrien de Sentenac Accédez au courrier 
>électronique de La Poste : www.laposte.net ; 
>3615 LAPOSTENET (0,34€/mn) ; tél : 08 92 68 13 50 (0,34€/mn)