Click to See Complete Forum and Search --> : How to get attribute data types with SAX (not CDATA)


lclarkjr
November 6th, 2003, 11:13 AM
How can i obtain attribute data types when parsing an xml file using SAX?

The ISAXAttributes::getType only returns CDATA, ID, etc. But i want the type of the attribute defined in the XSD such as xs:boolean, xs:string, etc.

I am using MSXML4 and C++.

lclarkjr
November 6th, 2003, 12:39 PM
I have found the solution!:)

//m_pSchemaElement is the schema returned
//in SAXInterface::schemaElementDecl for the current element
MSXML2::ISchemaTypePtr pElementSchema = NULL;
m_pSchemaElement->get_type(&pElementSchema);

//cast the schema as a complex type
MSXML2::ISchemaComplexTypePtr pComplexSchemaType;
pComplexSchemaType = pElementSchema;

//now we can get the collection of attributes from the schema
MSXML2::ISchemaItemCollectionPtr pAttributes;
pComplexSchemaType->get_attributes( &pAttributes);

//find the attribute of interest
MSXML2::ISchemaItemPtr pAttribute;
pAttributes->get_item(i,&pAttribute);

//BSTR tmpName;
//pAttribute->get_name(&tmpName);

//cast the attribute ISchemaItem as a ISchemaAttribute object
MSXML2::ISchemaAttributePtr pAttributeSchema;
pAttributeSchema = pAttribute;

//now we can get the type object for the attribute
MSXML2::ISchemaTypePtr pAttributeType;
pAttributeSchema->get_type(&pAttributeType);

//and finally get the attribute data type
MSXML2::SOMITEMTYPE siType;
pAttributeType->get_itemType(&siType);