// ---------------------------------------------------------------------------
//  This method assumes that currentNode is an xinclude element and parses
//   it accordingly, acting on what it finds.
// ---------------------------------------------------------------------------
bool
XIncludeUtils::doDOMNodeXInclude(DOMNode *xincludeNode, DOMDocument *parsedDocument, XMLEntityHandler* entityResolver){
    bool modifiedNode = false;
    /* the relevant attributes to look for */
    const XMLCh *href = NULL;
    const XMLCh *parse = NULL;
    const XMLCh *xpointer = NULL;
    const XMLCh *encoding = NULL;
    const XMLCh *accept = NULL;
    const XMLCh *acceptlanguage = NULL;
    DOMNode *includeParent = xincludeNode->getParentNode();


    if(xincludeNode->hasAttributes()) {
        /* get all the attributes of the node */
        DOMNamedNodeMap *pAttributes = xincludeNode->getAttributes();
        XMLSize_t nSize = pAttributes->getLength();
        for(XMLSize_t i=0;i<nSize;++i) {
            DOMAttr *pAttributeNode = (DOMAttr*) pAttributes->item(i);
            const XMLCh *attrName = pAttributeNode->getName();
            /* check each attribute against the potential useful names */
            if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeHREFAttrName)){
                href = pAttributeNode->getValue();
            } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeParseAttrName)){
                parse = pAttributeNode->getValue();
            } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeXPointerAttrName)){
                xpointer = pAttributeNode->getValue();
            } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeEncodingAttrName)){
                encoding = pAttributeNode->getValue();
            } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeAcceptAttrName)){
                accept = pAttributeNode->getValue();
            } else if (XMLString::equals(attrName, XIncludeUtils::fgXIIncludeAcceptLanguageAttrName)){
                acceptlanguage = pAttributeNode->getValue();
            } else {
                /* if any other attribute is in the xi namespace, it's an error */
                const XMLCh *attrNamespaceURI = pAttributeNode->getNamespaceURI();
                if (attrNamespaceURI && XMLString::equals(attrNamespaceURI, XIncludeUtils::fgXIIIncludeNamespaceURI)){
                } else {
                    /* ignore - any other attribute is allowed according to spec,
                       and must be ignored */
                }
            }
        }
    }
    // 3.1 xi:include Element
    // The children property of the xi:include element may include a single xi:fallback element;
    // the appearance of more than one xi:fallback element, an xi:include element,
    // or any other element from the XInclude namespace is a fatal error.
    DOMNode *child;
    DOMElement *fallback = NULL;
    for (child = xincludeNode->getFirstChild(); child != 0; child=child->getNextSibling()){
        if(child->getNodeType()!=DOMNode::ELEMENT_NODE)
            continue;
        if ( isXIFallbackDOMNode(child) ){
            if (fallback != NULL){
                /* fatal error - there are more than one fallback children */
                XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeMultipleFallbackElems,
                    parsedDocument->getDocumentURI(), parsedDocument->getDocumentURI());
                return false;
            }
            fallback = (DOMElement*)child;
        }
        else if(isXIIncludeDOMNode(child) || XMLString::equals(child->getNamespaceURI(), XIncludeUtils::fgXIIIncludeNamespaceURI)) {
            /* fatal error - an xi element different from xi:fallback is a child of xi:include */
            XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeDisallowedChild,
                child->getNodeName(), parsedDocument->getDocumentURI());
            return false;
        }
    }

    if (href == NULL){
        /* this is an unrecoverable error until we have xpointer support -
           if there is an xpointer, the current document is assumed
           however, there is no xpointer support yet */
        XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeNoHref,
            NULL, parsedDocument->getDocumentURI());
        return false;
    }

    /* set up the accept and accept-language values */
    if (accept != NULL){

    }

    if (parse == NULL){
        /* use the default, as specified */
        parse = XIncludeUtils::fgXIIncludeParseAttrXMLValue;
    }

    if (xpointer != NULL){
        /* not supported yet */
        /* Note that finding an xpointer attr along with parse="text" is a Fatal Error
         *  - http://www.w3.org/TR/xinclude/#include-location */
        XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeXPointerNotSupported,
            NULL, href);
        return false;
    }

    /* set up the href according to what has gone before */
    XIncludeLocation hrefLoc(href);
    XIncludeLocation relativeLocation(href);
    const XMLCh *includeBase = xincludeNode->getBaseURI();
    if (includeBase != NULL){
        hrefLoc.prependPath(includeBase);
    }

    if (getBaseAttrValue(xincludeNode) != NULL){
        relativeLocation.prependPath(getBaseAttrValue(xincludeNode));
    }

    /*  Take the relevant action - we need to retrieve the target as a whole before
        we can know if it was successful or not, therefore the do* methods do
        not modify the parsedDocument. Swapping the results in is left to the
        caller (i.e. here) */
    DOMText *includedText = NULL;
    DOMDocument *includedDoc = NULL;
    if (XMLString::equals(parse, XIncludeUtils::fgXIIncludeParseAttrXMLValue)){
        /* including a XML element */
        includedDoc = doXIncludeXMLFileDOM(hrefLoc.getLocation(), relativeLocation.getLocation(), xincludeNode, parsedDocument, entityResolver);
    } else if (XMLString::equals(parse, XIncludeUtils::fgXIIncludeParseAttrTextValue)){
        /* including a text value */
        includedText = doXIncludeTEXTFileDOM(hrefLoc.getLocation(), relativeLocation.getLocation(), encoding, xincludeNode, parsedDocument, entityResolver);
    } else {
        /* invalid parse attribute value - fatal error according to the specification */
        XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeInvalidParseVal,
            parse, parsedDocument->getDocumentURI());
        return false;
    }

    RefVectorOf<DOMNode> delayedProcessing(12,false);
    if (includedDoc == NULL && includedText == NULL){
        /* there was an error - this is now a resource error
           let's see if there is a fallback */
        XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeIncludeFailedResourceError,
            hrefLoc.getLocation(), parsedDocument->getDocumentURI());

        if (includeParent == NULL){
            includeParent = parsedDocument;
        }

        // we could be getting errors trying to insert elements at the root of the document, so we should use replaceChild;
        // in order to handle multiple nodes, add them to a document fragment and use that to replace the original node
        if (fallback){
            /* baseURI fixups - see http://www.w3.org/TR/xinclude/#base for details. */
            XMLUri parentURI(includeParent->getBaseURI());
            XMLUri includedURI(fallback->getBaseURI());

            if (fallback->hasChildNodes()){
                DOMDocumentFragment* frag = parsedDocument->createDocumentFragment();
                DOMNode *child = fallback->getFirstChild();
                /* add the content of the fallback element, and remove the fallback elem itself */
                for ( ; child != NULL ; child=child->getNextSibling()){
                    if (child->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE){
                        continue;
                    }
                    DOMNode *newNode = parsedDocument->importNode(child, true);
                    /* if the paths differ we need to add a base attribute */
                    if (newNode->getNodeType()==DOMNode::ELEMENT_NODE && !XMLString::equals(parentURI.getPath(), includedURI.getPath())){
                        if (getBaseAttrValue(newNode) == NULL){
                            /* need to calculate the proper path difference to get the relativePath */
                            ((DOMElement*)newNode)->setAttribute(fgXIBaseAttrName, getBaseAttrValue(fallback->getParentNode()));
                        } else {
                            /* the included node has base of its own which takes precedence */
                            XIncludeLocation xil(getBaseAttrValue(newNode));
                            if (getBaseAttrValue(fallback->getParentNode()) != NULL){
                                /* prepend any specific base modification of the xinclude node */
                                xil.prependPath(getBaseAttrValue(fallback->getParentNode()));
                            }
                            ((DOMElement*)newNode)->setAttribute(fgXIBaseAttrName, xil.getLocation());
                        }
                    }
                    DOMNode *newChild = frag->appendChild(newNode);
                    // don't process the node now, wait until it is placed in the final position
                    delayedProcessing.addElement(newChild);
                    //parseDOMNodeDoingXInclude(newChild, parsedDocument, entityResolver);
                }
                includeParent->replaceChild(frag, xincludeNode);
                frag->release();

                for(XMLSize_t i=0;i<delayedProcessing.size();i++)
                {
                    DOMNode* childNode=delayedProcessing.elementAt(i);
                    parseDOMNodeDoingXInclude(childNode, parsedDocument, entityResolver);
                }
                modifiedNode = true;
            } else {
                /* empty fallback element - simply remove it! */
                includeParent->removeChild(xincludeNode);
                modifiedNode = true;
            }
        } else {
            XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeIncludeFailedNoFallback,
                parsedDocument->getDocumentURI(), parsedDocument->getDocumentURI());
            return false;
        }
    } else {
        if (includedDoc){
            /* record the successful include while we process the children */
            addDocumentURIToCurrentInclusionHistoryStack(hrefLoc.getLocation());

            DOMDocumentFragment* frag = parsedDocument->createDocumentFragment();
            /* need to import the document prolog here */
            DOMNode *child = includedDoc->getFirstChild();
            for (; child != NULL; child = child->getNextSibling()) {
                if (child->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE)
                    continue;
                // check for NOTATION or ENTITY clash
                if(child->getNodeType()==DOMNode::ELEMENT_NODE && includedDoc->getDoctype()!=NULL) {
                    DOMNamedNodeMap *pAttributes = child->getAttributes();
                    XMLSize_t nSize = pAttributes->getLength();
                    for(XMLSize_t i=0;i<nSize;++i) {
                        DOMAttr *pAttributeNode = (DOMAttr*) pAttributes->item(i);
                        const DOMTypeInfo * typeInfo=pAttributeNode->getSchemaTypeInfo();
                        if(typeInfo && XMLString::equals(typeInfo->getTypeNamespace(), XMLUni::fgInfosetURIName)) {
                            if(XMLString::equals(typeInfo->getTypeName(), XMLUni::fgNotationString)) {
                                const XMLCh* notationName=pAttributeNode->getNodeValue();
                                DOMNotation* notat=(DOMNotation*)includedDoc->getDoctype()->getNotations()->getNamedItem(notationName);
                                // ensure we have a DTD
                                if(parsedDocument->getDoctype()==NULL)
                                    parsedDocument->insertBefore(parsedDocument->createDocumentType(parsedDocument->getDocumentElement()->getNodeName(), NULL,NULL), parsedDocument->getFirstChild());
                                DOMNotation* myNotation=(DOMNotation*)parsedDocument->getDoctype()->getNotations()->getNamedItem(notationName);
                                if(myNotation==NULL)
                                {
                                    // it's missing, add it
                                    parsedDocument->getDoctype()->getNotations()->setNamedItem(parsedDocument->importNode(notat, true));
                                }
                                else if(XMLString::equals(myNotation->getPublicId(), notat->getPublicId()) &&
                                        XMLString::equals(myNotation->getSystemId(), notat->getSystemId()) &&
                                        XMLString::equals(myNotation->getBaseURI(), notat->getBaseURI()))
                                {
                                    // it's duplicate, ignore it
                                }
                                else
                                {
                                    // it's a conflict, report it
                                    XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeConflictingNotation,
                                        notationName, parsedDocument->getDocumentURI());
                                }
                            }
                            else if(XMLString::equals(typeInfo->getTypeName(), XMLUni::fgEntityString)) {
                                const XMLCh* entityName=pAttributeNode->getNodeValue();
                                DOMEntity* ent=(DOMEntity*)includedDoc->getDoctype()->getEntities()->getNamedItem(entityName);
                                // ensure we have a DTD
                                if(parsedDocument->getDoctype()==NULL)
                                    parsedDocument->insertBefore(parsedDocument->createDocumentType(parsedDocument->getDocumentElement()->getNodeName(), NULL,NULL), parsedDocument->getFirstChild());
                                DOMEntity* myEnt=(DOMEntity*)parsedDocument->getDoctype()->getEntities()->getNamedItem(entityName);
                                if(myEnt==NULL)
                                {
                                    // it's missing, add it
                                    parsedDocument->getDoctype()->getEntities()->setNamedItem(parsedDocument->importNode(ent, true));
                                }
                                else if(XMLString::equals(myEnt->getPublicId(), ent->getPublicId()) &&
                                        XMLString::equals(myEnt->getSystemId(), ent->getSystemId()) &&
                                        XMLString::equals(myEnt->getBaseURI(), ent->getBaseURI()))
                                {
                                    // it's duplicate, ignore it
                                }
                                else
                                {
                                    // it's a conflict, report it
                                    XIncludeUtils::reportError(xincludeNode, XMLErrs::XIncludeConflictingEntity,
                                        entityName, parsedDocument->getDocumentURI());
                                }
                            }
                        }
                    }
                }
                DOMNode *newNode = parsedDocument->importNode(child, true);
                DOMNode *newChild = frag->appendChild(newNode);
                // don't process the node now, wait until it is placed in the final position
                delayedProcessing.addElement(newChild);
                //parseDOMNodeDoingXInclude(newChild, parsedDocument, entityResolver);
            }
            includeParent->replaceChild(frag, xincludeNode);
            frag->release();

            for(XMLSize_t i=0;i<delayedProcessing.size();i++)
            {
                DOMNode* childNode=delayedProcessing.elementAt(i);
                parseDOMNodeDoingXInclude(childNode, parsedDocument, entityResolver);
            }
            popFromCurrentInclusionHistoryStack(NULL);
            modifiedNode = true;
        } else if (includedText){
            includeParent->replaceChild(includedText, xincludeNode);
            modifiedNode = true;
        }
    }

    if (includedDoc)
        includedDoc->release();

    return modifiedNode;
}
Exemple #2
0
/*!
	\brief It gets a list of DOM nodes containing a protocol, and formats them into _nbPDMLProto structures.

	This function converts each protocol and all its child fields. This function will call the FormatFieldsItem()
	for this purpose.

	\param PDMLDocument The DOMDocument associated to the current PDML packet.

	\return The number of '&lt;proto&gt;' that have been copied in the returned buffer, 
	nbFAILURE if some error occurred.
	The error message is stored in the m_errbuf internal buffer.
*/
int CPDMLReader::FormatProtoItem(DOMDocument *PDMLDocument)
{
DOMNodeList *ProtoList;
XMLCh TempBuffer[NETPDL_MAX_STRING + 1];
unsigned int ProtoNumber;
unsigned int TotNumProto;

	XMLString::transcode(PDML_PROTO, TempBuffer, NETPDL_MAX_STRING);

	// After parsing the '<packet>' fragment, let's list the <proto> contained into it
	ProtoList= PDMLDocument->getElementsByTagName(TempBuffer);

	// Get the number of protocols contained in this packet
	TotNumProto= ProtoList->getLength();

	// Check if the protocol structures allocated previously are enough. If not, let's allocate new structures
	if (TotNumProto >= m_maxNumProto)
	{
		if (UpdateProtoList(&m_maxNumProto, &m_protoList, m_errbuf, sizeof(m_errbuf)) == nbFAILURE)
			return nbFAILURE;
	}

	// Reset the buffer
	m_asciiBuffer.ClearBuffer(false /* resizing not permitted */);

	for (ProtoNumber= 0; ProtoNumber < TotNumProto; ProtoNumber++)
	{
	DOMElement *ProtoItem;

		// Set everything to zero
		memset(m_protoList[ProtoNumber], 0, sizeof(_nbPDMLProto));

		// Update pointer to the packet summary
		m_protoList[ProtoNumber]->PacketSummary= &m_packetSummary;

		// Updates the protocol chain
		if (ProtoNumber >= 1)
		{
			m_protoList[ProtoNumber - 1]->NextProto= m_protoList[ProtoNumber];
			m_protoList[ProtoNumber]->PreviousProto= m_protoList[ProtoNumber - 1];
		}

		ProtoItem= (DOMElement *) ProtoList->item(ProtoNumber);

		// Copies all the attributes of this proto in the new structure
 		if (AppendItemString(ProtoItem, PDML_FIELD_ATTR_NAME,
			&(m_protoList[ProtoNumber]->Name), &m_asciiBuffer, m_errbuf, sizeof(m_errbuf)) == nbFAILURE)
			return nbFAILURE;
 		if (AppendItemString(ProtoItem, PDML_FIELD_ATTR_LONGNAME,
			&(m_protoList[ProtoNumber]->LongName), &m_asciiBuffer, m_errbuf, sizeof(m_errbuf)) == nbFAILURE)
			return nbFAILURE;
		if (AppendItemLong(ProtoItem, PDML_FIELD_ATTR_SIZE,
			&(m_protoList[ProtoNumber]->Size), m_errbuf, sizeof(m_errbuf)) == nbFAILURE)
			return nbFAILURE;
		if (AppendItemLong(ProtoItem, PDML_FIELD_ATTR_POSITION,
			&(m_protoList[ProtoNumber]->Position), m_errbuf, sizeof(m_errbuf)) == nbFAILURE)
			return nbFAILURE;

#ifdef DOM_DEBUG
		// FULVIO This code is still present, because it should be needed in order to solve
		// a bug discovered on Dec 4, 2006
		// See my email in the mailbox
		// get a serializer, an instance of DOMWriter
		XMLCh tempStr[100];
		XMLString::transcode("LS", tempStr, 99);

		DOMImplementation *impl          = DOMImplementationRegistry::getDOMImplementation(tempStr);
		DOMWriter         *theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter();

		MemBufFormatTarget myFormTarget;

		theSerializer->writeNode(&myFormTarget, *ProtoItem);

		const XMLByte *Result= myFormTarget.getRawBuffer();

		delete theSerializer;
#endif

		if (ProtoItem->hasChildNodes() )
		{
			if (FormatFieldNodes(ProtoItem->getFirstChild(), m_protoList[ProtoNumber], NULL) == nbFAILURE)
				return nbFAILURE;
		}
	}

	// Update the pointer to the first protocol
	if (TotNumProto > 0)
		m_packetSummary.FirstProto= m_protoList[0];
	else
		m_packetSummary.FirstProto= NULL;

	return (int) ProtoNumber;
}
	Armor* ItemDataLoader::processArmor(DOMElement* armorXml)
	{
		// Itemname
		CeGuiString name = XmlHelper::getAttributeValueAsString(armorXml,"Name");
		// Beschreibung
		CeGuiString desc = XmlHelper::getAttributeValueAsString(armorXml,"Beschreibung");
		// Eindeutiger Zuordner
		CeGuiString id = XmlHelper::getAttributeValueAsString(armorXml,"ID");

		// Image fürs Inventar
		CeGuiString imageName = XmlHelper::getValueAsString(XmlHelper::getChildNamed(armorXml, "Bildname"));
		// Mesh für das Spiel
		DOMElement* meshNode = XmlHelper::getChildNamed(armorXml, "Mesh");
		CeGuiString mesh = "";
		if (meshNode->hasChildNodes())
		{
			mesh = XmlHelper::getValueAsString(meshNode);
		}
		CeGuiString typeString = XmlHelper::getValueAsString(XmlHelper::getChildNamed(armorXml, "Klasse"));
		Item::ItemType type = static_cast<Item::ItemType>(getItemTypeFromString(typeString));

		// Größe im Inventar
		int size_x = XmlHelper::getAttributeValueAsInteger(XmlHelper::getChildNamed(armorXml, "Größe"),"X");
		int size_y = XmlHelper::getAttributeValueAsInteger(XmlHelper::getChildNamed(armorXml, "Größe"),"Y");
		
		// Containerplatz für andere Gegenstände, die dieser aufnahmen kann
		int place_x = XmlHelper::getAttributeValueAsInteger(XmlHelper::getChildNamed(armorXml, "Platz"),"X");
		int place_y = XmlHelper::getAttributeValueAsInteger(XmlHelper::getChildNamed(armorXml, "Platz"),"Y");

		// Rüstungsschutz für bestimmte Zonen
		int ko = XmlHelper::getValueAsInteger(XmlHelper::getChildNamed(armorXml, "Ko"));
		int br = XmlHelper::getValueAsInteger(XmlHelper::getChildNamed(armorXml, "Br"));
		int rue = XmlHelper::getValueAsInteger(XmlHelper::getChildNamed(armorXml, "Rü"));
		int ba = XmlHelper::getValueAsInteger(XmlHelper::getChildNamed(armorXml, "Ba"));
		int la = XmlHelper::getValueAsInteger(XmlHelper::getChildNamed(armorXml, "LA"));
		int ra = XmlHelper::getValueAsInteger(XmlHelper::getChildNamed(armorXml, "RA"));
		int lb = XmlHelper::getValueAsInteger(XmlHelper::getChildNamed(armorXml, "LB"));
		int rb = XmlHelper::getValueAsInteger(XmlHelper::getChildNamed(armorXml, "RB"));
		int ges = XmlHelper::getValueAsInteger(XmlHelper::getChildNamed(armorXml, "Ges."));
		int grs = XmlHelper::getValueAsInteger(XmlHelper::getChildNamed(armorXml, "gRs"));
		int gbe = XmlHelper::getValueAsInteger(XmlHelper::getChildNamed(armorXml, "gBe"));

		int gewicht = XmlHelper::getValueAsInteger(XmlHelper::getChildNamed(armorXml, "Gewicht"));

		int preis = XmlHelper::getValueAsInteger(XmlHelper::getChildNamed(armorXml, "Preis"));

		// Neuen Rüstungsprototyp erzeugen und zurückgeben
		Armor* a = new Armor(
			name,
			desc
			);
		a->setImageName(imageName);
		a->setMeshName(mesh);
		a->setItemType(type);
		a->setSize(size_x,size_y);
		if (place_x > 0 && place_y > 0)
		{
			a->setContainer(true,make_pair<int,int>(place_x,place_y));
		}
		a->setKo(ko);
		a->setBr(br);
		a->setRue(rue);
		a->setBa(ba);
		a->setLA(la);
		a->setRA(ra);
		a->setLB(lb);
		a->setRB(rb);
		a->setGes(ges);
		a->setGRS(grs);
		a->setGBE(gbe);
		// Umrechnung Stein->Unzen = Mal 40
		a->setWeight(gewicht * 40);
		a->setPrice(preis);
        return a;
    }
Exemple #4
0
XERCES_CPP_NAMESPACE_USE

int main( int argc, char *argv[] )
{
    std::cout << "****************************" << std::endl;
    std::cout << "XML DOM PARSER PLAY" << std::endl;
    std::cout << "****************************" << std::endl;

    try
    {
        XMLPlatformUtils::Initialize();
    }
    catch( const XMLException& ex )
    {
        std::cerr << "error with xml initialisation:" << ex.getMessage() << std::endl;
        return 1;
    }

    std::cout << "Building parser ..." << std::endl;
    XercesDOMParser* parser = new XercesDOMParser();
    if( !parser )
    {
        std::cerr << "no parser" << std::endl;
        return 1;
    }
    parser->setValidationScheme(XercesDOMParser::Val_Always);
    parser->setDoNamespaces(false);
    parser->setDoSchema(false);
    parser->setCreateEntityReferenceNodes(false);

    std::cout << "Building error handler" << std::endl;
    ErrorHandler* errHandler = dynamic_cast<ErrorHandler*>(new HandlerBase());
    if( errHandler == 0 )
    {
        std::cerr << "ibad cast" << std::endl;
        return 1;
    } 
    
    if( errHandler == 0 )
    {
        std::cerr << "error with errorhandler caszting:" << std::endl;
        return 1;
    }
    parser->setErrorHandler(errHandler);

    char* xmlFile = "/home/suggitpe/test/RPMS/config/rpms_config.xml";
    try
    {
        parser->parse(xmlFile);
        if( parser->getErrorCount() == 0 )
        {
            std::cerr << "errors in parsing" << std::endl;
            return 1;
        }
        DOMDocument * doc = parser->getDocument();
        if( doc->hasChildNodes() )
        {
            std::cout << "Num nodes: " << doc->getChildNodes()->getLength() << std::endl;
            for( int i = 0; i < doc->getChildNodes()->getLength();++i )
            {
                cout << "\t" << i << " type: " << doc->getChildNodes()->item(i)->getNodeType() << endl;
                if( doc->getChildNodes()->item(i)->getNodeType() == 1 )
                {
                    DOMElement *e = dynamic_cast<DOMElement*>(doc->getChildNodes()->item(i));
                    if( !e ) { cerr << "bad cast" << endl; }
                    if( e->hasChildNodes() )
                    {
                        cout << "\t\telement found with " << e->getChildNodes()->getLength() << " nodes"<< endl;
                    }
                    else
                    {
                        cout << "No child nodes" << endl;
                    }
                }
            }

            cout << "now for the other way" << endl;
            XMLCh * name = XMLString::transcode("system_components");
            DOMNodeList *list = doc->getDocumentElement()->getElementsByTagName( name );
            XMLString::release(&name);
            
            std::cout << "Got list [" << list->getLength() << "]" << std::endl;
            for( XMLSize_t i =0; i < list->getLength(); ++i )
            {
                std::cout << "." << std::endl;
            }
        }
        else
        {
            std::cout << "no child nodes" << std::endl;
        }
    }
    catch( const XMLException& ex )
    {
        std::cerr << "error with xml parser:" << ex.getMessage() << std::endl;
        return 1;
    }
    catch( const DOMException& dex )
    {
        std::cerr << "error with xml parser:" << dex.msg << std::endl;
        return 1;
    }
    catch(...)
    {
        std::cerr << "unknown problems" << std::endl;
        return 1;
            
    }
    delete parser;
    delete errHandler;

    std::cout << "****************************" << std::endl;
    std::cout << "" << std::endl;
    return 0;
}