InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ISAXAttributes Class Referenceabstract

#include <ISAXAttributes.h>

Inheritance diagram for ISAXAttributes:
IPMUnknown

Public Types

enum  { kDefaultIID = IID_ISAXATTRIBUTES }
 
typedef std::vector< std::pair
< WideString, WideString > > 
NamespaceDecl
 

Public Member Functions

virtual void Adopt (const char **attributes, bool16 namespaced, ISAXServices *owner, const NamespaceDecl &namespaceDecls)=0
 
virtual int32 GetLength () const =0
 
virtual void AttributeHandled (uint32 index)=0
 
virtual bool16 GetURI (uint32 index, WideString &uri) const =0
 
virtual bool16 GetLocalName (uint32 index, WideString &localName) const =0
 
virtual bool16 GetQName (uint32 index, WideString &qName) const =0
 
virtual bool16 GetType (uint32 index, WideString &attributeType) const =0
 
virtual bool16 GetValue (uint32 index, WideString &attributeValue) const =0
 
virtual bool16 GetIndex (const WideString &uri, const WideString &localPart, uint32 &index) const =0
 
virtual bool16 GetIndex (const WideString &qName, uint32 &index) const =0
 
virtual bool16 GetType (const WideString &uri, const WideString &localPart, WideString &attributeType) const =0
 
virtual bool16 GetType (const WideString &qName, WideString &attributeType) const =0
 
virtual bool16 GetValue (const WideString &uri, const WideString &localPart, WideString &attributeValue) const =0
 
virtual bool16 GetValue (const WideString &qName, WideString &attributeValue) const =0
 
virtual bool16 HasAttribute (const PMString &key) const =0
 
virtual bool16 HasAttribute (const WideString &key) const =0
 
virtual PMString GetAttributeString (const PMString &key, const PMString &defaultValue="") const =0
 
virtual WideString GetAttributeString (const WideString &key, const WideString *defaultValue=nil) const =0
 
virtual bool16 GetAttributeBool (const PMString &key, bool16 defaultValue=kFalse) const =0
 
virtual bool16 GetAttributeBool (const WideString &key, bool16 defaultValue=kFalse) const =0
 
virtual int32 GetAttributeInt (const PMString &key, int32 defaultValue=0) const =0
 
virtual int32 GetAttributeInt (const WideString &key, int32 defaultValue=0) const =0
 
- Public Member Functions inherited from IPMUnknown
virtual IPMUnknownQueryInterface (PMIID interfaceID) const =0
 
virtual void AddRef () const =0
 
virtual void Release () const =0
 

Detailed Description

An InDesign friendly Wrapper for attributes in Expat. An instance of this class will be passed to ISaxContentHandler::StartElement.

An element's attributes

The instance provided will return valid results only during the scope of the startElement invocation. To save it for future use, the application must make a copy.

There are two ways for the SAX application to obtain information from the ISAXAttributes interface. First, it can iterate through the entire list:


StartElement(const WideString& uri, const WideString& localname,

const WideString& qname, ISAXAttributes* attrs) {

  for (unsigned int i = 0; i < atts->GetLength(); i++) {

    WideString Qname, URI, local, type, value;

    if (!atts->getQName(i, Qname)) ...

    if (!atts->getURI(i, URI)) ...

    if (!atts->getLocalName(i, local)) ...

    if (!atts->getType(i, type)) ...

    if (!atts->getValue(i, value)) ...

    [...]

  }

}

(Note: The result of GetLength() will be zero if there are no attributes.)

As an alternative, the application can request the value or type of specific attributes by qualified name or by fully expanded name with namespace:


StartElement(const WideString& uri, const WideString& localname,

const WideString& qname, ISAXAttributes* attrs) {

  WideString identifier;

  if (!atts->GetValue("id", identifier)) ...

  WideString label;

  if (!atts->GetValue("label", label)) ...

  [...]

}

Invalid Parameters

See Also
ISAXContentHandler::StartElement

Member Function Documentation

virtual void ISAXAttributes::Adopt (const char ** attributes,
bool16 namespaced,
ISAXServicesowner,
const NamespaceDecl & namespaceDecls 
)
pure virtual

Adopt an instance of attributes provided by the parser. This is not intended to be used by clients.

'attributes' is an array of name/value pairs, terminated by 0; names and values are 0 terminated. The name of each attribute may include the namespace URI and the prefix, depending on the parser options.

Namespace declarations are not included in 'attributes'. 'namespaceDecls' contains namespace declarations in the same scope of 'attributes'.

virtual void ISAXAttributes::AttributeHandled (uint32 index)
pure virtual

Mark an attribute as handled so that other attribute handlers will not have to try and deal with it.

Parameters
indexThe index of the attribute in the list (starting at 0).
virtual bool16 ISAXAttributes::GetIndex (const WideStringuri,
const WideStringlocalPart,
uint32 & index 
) const
pure virtual

Index by namespace name

Parameters
uriThe Namespace URI, or the empty string if the name has no Namespace URI.
localPartThe attribute's local name.
indexOutput of index if returned true.
Returns
kFalse if no such attribute, true otherwise.
virtual bool16 ISAXAttributes::GetIndex (const WideStringqName,
uint32 & index 
) const
pure virtual

Index by XML 1.0 qualified name

Parameters
qNameThe qualified (prefixed) name.
indexOutput of index if returned true.
Returns
kFalse if no such attribute, true otherwise.
virtual int32 ISAXAttributes::GetLength () const
pure virtual

Number of attributes in this list

The SAX parser may provide attributes in any arbitrary order, regardless of the order in which they were declared or specified. The number of attributes may be zero.

Returns
The number of attributes in the list.
virtual bool16 ISAXAttributes::GetLocalName (uint32 index,
WideStringlocalName 
) const
pure virtual

Local name of an attribute by position

The QNames must be unique: the SAX parser shall not include the same attribute twice. Attributes without values (those declared #IMPLIED without a value specified in the start tag) will be omitted from the list.

Parameters
indexThe index of the attribute in the list (starting at 0).
localNameThe output parameter specified by the caller to contain the returned local name of the indexed attribute.
Returns
kFalse if the index is out of range, true otherwise.
See Also
GetLength
virtual bool16 ISAXAttributes::GetQName (uint32 index,
WideStringqName 
) const
pure virtual

QName of an attribute by position

The QNames must be unique: the SAX parser shall not include the same attribute twice. Attributes without values (those declared #IMPLIED without a value specified in the start tag) will be omitted from the list.

Parameters
indexThe index of the attribute in the list (starting at 0).
qNameThe output parameter specified by the caller to contain the returned QName of the indexed attribute.
Returns
kFalse if the index is out of range, true otherwise.
See Also
GetLength
virtual bool16 ISAXAttributes::GetType (uint32 index,
WideStringattributeType 
) const
pure virtual

Return the type of an attribute in the list (by position).

The attribute type is one of the strings "CDATA", "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", or "NOTATION" (always in upper case).

If the parser has not read a declaration for the attribute, or if the parser does not report attribute types, then it must return the value "CDATA" as stated in the XML 1.0 Recommentation (clause 3.3.3, "Attribute-Value Normalization").

For an enumerated attribute that is not a notation, the parser will report the type as "NMTOKEN".

Parameters
indexThe index of the attribute in the list (starting at 0).
attributeTypeThe output parameter specified by the caller to contain the returned type string of the indexed attribute.
Returns
kFalse if the index is out of range, true otherwise.
See Also
GetLength
#GetType(String)
virtual bool16 ISAXAttributes::GetType (const WideStringuri,
const WideStringlocalPart,
WideStringattributeType 
) const
pure virtual

Type by namespace name

See GetType for a description of the possible types.

Parameters
uriThe namespace URI, or the empty string if the name has no namespace URI.
localPartThe local name of the attribute.
attributeTypeThe output parameter specified by the caller to contain the returned type string of the named attribute.
Returns
kFalse if the attribute is not in the list or if namespace processing is not being performed, true otherwise.
virtual bool16 ISAXAttributes::GetType (const WideStringqName,
WideStringattributeType 
) const
pure virtual

Type by qualified name

See GetType for a description of the possible types.

Parameters
qNameThe XML 1.0 qualified name.
attributeTypeThe output parameter specified by the caller to contain the returned type string of the named attribute.
Returns
kFalse if the attribute is not in the list or if qualified names are not available, true otherwise.
virtual bool16 ISAXAttributes::GetURI (uint32 index,
WideStringuri 
) const
pure virtual

Namespace URI of an attribute by position

The QNames must be unique: the SAX parser will not include the same attribute twice. Attributes without values (those declared #IMPLIED without a value specified in the start tag) will be omitted from the list.

Parameters
indexThe index of the attribute in the list (starting at 0).
uriThe output parameter specified by the caller to contain the returned URI.
Returns
kFalse if the index is out of range, true otherwise.
See Also
GetLength
virtual bool16 ISAXAttributes::GetValue (uint32 index,
WideStringattributeValue 
) const
pure virtual

Value of an attribute by position

If the attribute value is a list of tokens (IDREFS, ENTITIES, or NMTOKENS), the tokens will be concatenated into a single string separated by whitespace.

Parameters
indexThe index of the attribute in the list (starting at 0).
attributeValueThe output parameter specified by the caller to contain the returned value of the indexed attribute.
Returns
kFalse if the index is out of range, true otherwise.
See Also
GetLength
GetValue
virtual bool16 ISAXAttributes::GetValue (const WideStringuri,
const WideStringlocalPart,
WideStringattributeValue 
) const
pure virtual

Value by namespace name

Parameters
uriThe namespace URI, or the empty String if the name has no Namespace URI.
localPartThe local name of the attribute.
attributeValueThe output parameter specified by the caller to contain the returned value of the named attribute.
Returns
kFalse if the attribute is not in the list, true otherwise.
virtual bool16 ISAXAttributes::GetValue (const WideStringqName,
WideStringattributeValue 
) const
pure virtual

Look up an attribute's value by XML 1.0 qualified name.

Parameters
qNameThe XML 1.0 qualified name.
attributeValueThe output parameter specified by the caller to contain the returned value of the named attribute.
Returns
kFalse if the attribute is not in the list or if qualified names are not available, true otherwise.
virtual bool16 ISAXAttributes::HasAttribute (const PMStringkey) const
pure virtual

Convenience methods to easily extract basic types from a set of attributes. If the attribute exists, it will extract the basic type from it. If it doesn't exist, it returns the default value you passed in.