Exemple #1
0
// ---------------------------------------------------------------------------
//  The virtual element decl interface
// ---------------------------------------------------------------------------
XMLAttDef* DTDElementDecl::findAttr(const   XMLCh* const    qName
                                    , const unsigned int
                                    , const XMLCh* const
                                    , const XMLCh* const
                                    , const LookupOpts      options
                                    ,       bool&           wasAdded) const
{
    DTDAttDef* retVal = 0;

    // If no att list faulted in yet, then it cannot exist
    if (fAttDefs)
        retVal = fAttDefs->get(qName);

    // Fault it in if not found and ask to add it
    if (!retVal && (options == XMLElementDecl::AddIfNotFound))
    {
        // Fault in the list itself if not already
        if (!fAttDefs)
            faultInAttDefList();

        // And add a default attribute for this name
        retVal = new (getMemoryManager()) DTDAttDef
        (
            qName
            , XMLAttDef::CData
            , XMLAttDef::Implied
            , getMemoryManager()
        );
        retVal->setElemId(getId());
        fAttDefs->put((void*)retVal->getFullName(), retVal);
        // update and/or create fAttList
        if(!fAttList)
            ((DTDElementDecl*)this)->fAttList = new (getMemoryManager()) DTDAttDefList(fAttDefs,getMemoryManager());
        fAttList->addAttDef(retVal);

        wasAdded = true;
    }
     else
    {
        wasAdded = false;
    }
    return retVal;
}
// -----------------------------------------------------------------------
//  TestParser: The DocTypeHandler interface
// -----------------------------------------------------------------------
void TestParser::attDef(const   DTDElementDecl& elemDecl
                        , const DTDAttDef&      attDef
                        , const bool            ignoring)
{
    if (fOutputType == OutputType_Debug)
    {
        XERCES_STD_QUALIFIER cout << "Got ATTDEF:\n    "
             << "Name: " << StrX(attDef.getFullName())
             << ", Type: "
             << StrX(XMLAttDef::getAttTypeString(attDef.getType()))
             << ", DefType: "
             << StrX(XMLAttDef::getDefAttTypeString(attDef.getDefaultType()));

        if (XMLString::stringLen(attDef.getValue()))
            XERCES_STD_QUALIFIER cout << ", Value: \"" << StrX(attDef.getValue()) << '"';

        XERCES_STD_QUALIFIER cout << "\n    SrcOfs: " << fScanner->getSrcOffset()
             << "\n" << XERCES_STD_QUALIFIER endl;
    }
     else if (fOutputType != OutputType_None)
    {
        if (fInExtSubset)
            return;

        if (fIntDTDOutput)
        {
            XERCES_STD_QUALIFIER cout << StrX(attDef.getFullName()) << " ";
            if (attDef.getType() == XMLAttDef::Enumeration)
            {
                XERCES_STD_QUALIFIER cout << '(';
                StrX tmpStr(attDef.getEnumeration());
                const char* curCh = tmpStr.localForm();
                while (*curCh)
                {
                    while (!isspace(*curCh) && *curCh)
                        XERCES_STD_QUALIFIER cout << *curCh++;

                    if (*curCh)
                    {
                        XERCES_STD_QUALIFIER cout << '|';
                        curCh++;
                    }
                }
                XERCES_STD_QUALIFIER cout << ')';
            }
             else
            {
                XERCES_STD_QUALIFIER cout << StrX(XMLAttDef::getAttTypeString(attDef.getType()));
            }

            if (XMLString::stringLen(attDef.getValue()))
                XERCES_STD_QUALIFIER cout << " \"" << StrX(attDef.getValue()) << '"';

            if (attDef.getDefaultType() != XMLAttDef::Default)
            {
                XERCES_STD_QUALIFIER cout << " "
                     << StrX(XMLAttDef::getDefAttTypeString(attDef.getDefaultType()));
            }
        }
    }
}
Exemple #3
0
// ---------------------------------------------------------------------------
//  NsSAX2Reader: Overrides of the DocTypeHandler interface
// ---------------------------------------------------------------------------
void NsSAX2Reader::attDef(const DTDElementDecl& elemDecl,
			   const DTDAttDef& attDef,
			   const_bool ignoring)
{
	if (fReadingIntSubset) {
		if (elemDecl.hasAttDefs()) {
			fSubset.append(attDef.getFullName());

			// Get the type and display it
			const XMLAttDef::AttTypes type = attDef.getType();
			switch(type)
			{
			case XMLAttDef::CData :
				fSubset.append(chSpace);
				fSubset.append(XMLUni::fgCDATAString);
				break;
			case XMLAttDef::ID :
				fSubset.append(chSpace);
				fSubset.append(XMLUni::fgIDString);
				break;
			case XMLAttDef::IDRef :
				fSubset.append(chSpace);
				fSubset.append(XMLUni::fgIDRefString);
				break;
			case XMLAttDef::IDRefs :
				fSubset.append(chSpace);
				fSubset.append(XMLUni::fgIDRefsString);
				break;
			case XMLAttDef::Entity :
				fSubset.append(chSpace);
				fSubset.append(XMLUni::fgEntityString);
				break;
			case XMLAttDef::Entities :
				fSubset.append(chSpace);
				fSubset.append(XMLUni::fgEntitiesString);
				break;
			case XMLAttDef::NmToken :
				fSubset.append(chSpace);
				fSubset.append(XMLUni::fgNmTokenString);
				break;
			case XMLAttDef::NmTokens :
				fSubset.append(chSpace);
				fSubset.append(XMLUni::fgNmTokensString);
				break;

			case XMLAttDef::Notation :
				fSubset.append(chSpace);
				fSubset.append(XMLUni::fgNotationString);
				break;

			case XMLAttDef::Enumeration :
				{
				fSubset.append(chSpace);
				const XMLCh* enumString = attDef.getEnumeration();
				int length = (int) XercesStringLen(enumString);
				if (length > 0) {

					fSubset.append(chOpenParen );
					for(int i=0; i<length; i++) {
						if (enumString[i] == chSpace)
							fSubset.append(chPipe);
						else
							fSubset.append(enumString[i]);
					}
					fSubset.append(chCloseParen);
				}
				}
				break;
			default :
				break;
			}
			//get te default types of the attlist
			const XMLAttDef::DefAttTypes def = attDef.getDefaultType();
			switch(def)
			{
			case XMLAttDef::Required :
				fSubset.append(chSpace);
				fSubset.append(XMLUni::fgRequiredString);
				break;
			case XMLAttDef::Implied :
				fSubset.append(chSpace);
				fSubset.append(XMLUni::fgImpliedString);
				break;
			case XMLAttDef::Fixed :
				fSubset.append(chSpace);
				fSubset.append(XMLUni::fgFixedString);
				break;
			default :
				break;
			}

			const XMLCh* defaultValue = attDef.getValue();
			if (defaultValue != 0) {
				fSubset.append(chSpace);
				fSubset.append(chDoubleQuote);
				fSubset.append(defaultValue);
				fSubset.append(chDoubleQuote);
			}
		}
	}
}