Add XML_GetSpecifiedAttributeCount().

This commit is contained in:
James Clark 1999-03-26 03:53:05 +00:00
parent 87d01c84d2
commit d2c1656f5f
3 changed files with 21 additions and 1 deletions

View file

@ -309,6 +309,7 @@ typedef struct {
BINDING *inheritedBindings;
BINDING *freeBindingList;
int attsSize;
int nSpecifiedAtts;
ATTRIBUTE *atts;
POSITION position;
STRING_POOL tempPool;
@ -376,6 +377,7 @@ typedef struct {
#define tagStack (((Parser *)parser)->tagStack)
#define atts (((Parser *)parser)->atts)
#define attsSize (((Parser *)parser)->attsSize)
#define nSpecifiedAtts (((Parser *)parser)->nSpecifiedAtts)
#define tempPool (((Parser *)parser)->tempPool)
#define temp2Pool (((Parser *)parser)->temp2Pool)
#define groupConnector (((Parser *)parser)->groupConnector)
@ -440,6 +442,7 @@ XML_Parser XML_ParserCreate(const XML_Char *encodingName)
inheritedBindings = 0;
attsSize = INIT_ATTS_SIZE;
atts = malloc(attsSize * sizeof(ATTRIBUTE));
nSpecifiedAtts = 0;
dataBuf = malloc(INIT_DATA_BUF_SIZE * sizeof(XML_Char));
groupSize = 0;
groupConnector = 0;
@ -635,6 +638,11 @@ const XML_Char *XML_GetBase(XML_Parser parser)
return dtd.base;
}
int XML_GetSpecifiedAttributeCount(XML_Parser parser)
{
return nSpecifiedAtts;
}
void XML_SetElementHandler(XML_Parser parser,
XML_StartElementHandler start,
XML_EndElementHandler end)
@ -1541,6 +1549,7 @@ static enum XML_Error storeAtts(XML_Parser parser, const ENCODING *enc,
else
attIndex++;
}
nSpecifiedAtts = attIndex;
if (tagNamePtr) {
int j;
for (j = 0; j < nDefaultAtts; j++) {

View file

@ -357,6 +357,12 @@ XML_SetBase(XML_Parser parser, const XML_Char *base);
const XML_Char XMLPARSEAPI *
XML_GetBase(XML_Parser parser);
/* Returns the number of the attributes passed in last call to the
XML_StartElementHandler that were specified in the start-tag rather
than defaulted. */
int XMLPARSEAPI XML_GetSpecifiedAttributeCount(XML_Parser parser);
/* Parses some input. Returns 0 if a fatal error is detected.
The last call to XML_Parse must have isFinal true;
len may be zero for this call (or any other). */

View file

@ -257,6 +257,8 @@ static
void metaStartElement(XML_Parser parser, const XML_Char *name, const XML_Char **atts)
{
FILE *fp = XML_GetUserData(parser);
const XML_Char **specifiedAttsEnd
= atts + 2*XML_GetSpecifiedAttributeCount(parser);
ftprintf(fp, T("<starttag name=\"%s\""), name);
metaLocation(parser);
if (*atts) {
@ -264,7 +266,10 @@ void metaStartElement(XML_Parser parser, const XML_Char *name, const XML_Char **
do {
ftprintf(fp, T("<attribute name=\"%s\" value=\""), atts[0]);
characterData(fp, atts[1], tcslen(atts[1]));
fputts(T("\"/>\n"), fp);
if (atts >= specifiedAttsEnd)
fputs(T("\" defaulted=\"yes\"/>\n"), fp);
else
fputts(T("\"/>\n"), fp);
} while (*(atts += 2));
fputts(T("</starttag>\n"), fp);
}