void mergeParts( DOMElement *part1, DOMElement *part2 ){ DOMElement *partDef1 = m_doc->getElementById(part1->getAttribute(XS("id"))); DOMElement *partDef2 = m_doc->getElementById(part2->getAttribute(XS("id"))); DOMNodeList *measures1 = part1->getElementsByTagName(XS("measure")); DOMNodeList *measures2 = part2->getElementsByTagName(XS("measure")); if(measures1->getLength() != measures2->getLength()) cerr << "parts are of different length!\n"; //Set part to have two staffs DOMElement *printEl = getSingleElement( (DOMElement*)measures1->item(0), "print" ); DOMElement *staffLayoutEl; DOMElement *numberEl; DOMElement *staffDistanceEl; if( printEl == NULL ){ cout << "Creating print element\n"; printEl = m_doc->createElement(XS("print")); staffLayoutEl = m_doc->createElement(XS("staff-layout")); numberEl = m_doc->createElement(XS("number")); staffDistanceEl = m_doc->createElement(XS("staff-distance")); ((DOMElement*)measures1->item(0))->insertBefore ( printEl, ((DOMElement*)measures1->item(0))->getFirstChild()); printEl->appendChild(staffLayoutEl); staffLayoutEl->appendChild(numberEl); staffLayoutEl->appendChild(staffDistanceEl); } else{ staffLayoutEl = getSingleElement( printEl, "staff-layout" ); numberEl = getSingleElement( staffLayoutEl, "number" ); staffDistanceEl = getSingleElement( staffLayoutEl, "staff-distance" ); } setText( numberEl, "2" ); setText( staffDistanceEl, "70"); //------------------------------------------------------------------------- DOMElement *attributes1 = getSingleElement( (DOMElement*)measures1->item(0), "attributes" ); DOMElement *attributes2 = getSingleElement( (DOMElement*)measures2->item(0), "attributes" ); // get lcd of divisions, and set in part1 int div1 = atoi( getText( getSingleElement( attributes1, "divisions" )).c_str()); int div2 = atoi( getText( getSingleElement( attributes2, "divisions" )).c_str()); int divlcm = lcm( div1, div2); cout << "Divs: " << div1 << " & " << div2 << " lcm " << divlcm << endl; setText(getSingleElement( attributes1, "divisions" ), itoa(divlcm) ); //get clefs, number tham and move clef2 into part1 DOMElement *clef1 = getSingleElement(attributes1,"clef"); DOMElement *clef2 = getSingleElement(attributes2,"clef"); clef1->setAttribute(XS("number"),XS(itoa(1).c_str())); clef2->setAttribute(XS("number"),XS(itoa(2).c_str())); //First, insert staves element DOMElement *stavesEl = m_doc->createElement(XS("staves")); setText(stavesEl, "2"); attributes1->appendChild(stavesEl); attributes1->appendChild(clef2); //get timesig & critchetsperbar DOMElement *tsEl = getSingleElement(attributes1,"time"); int tsn = atoi(getText(getSingleElement(tsEl,"beats")).c_str()); int tsd = atoi(getText(getSingleElement(tsEl,"beat-type")).c_str()); cout << "Time sig: " << tsn << "/" << tsd << endl; //calculate no of divisions per bar int divsperbar = divlcm * tsn / (tsd/4.0); cout << "Divs per bar: " << divsperbar << endl; //iterate through measures for(int i=0; i<measures1->getLength(); i++ ){ cout << "Altering bars " << i << endl; DOMElement *m1 = (DOMElement*)measures1->item(i); DOMElement *m2 = (DOMElement*)measures2->item(i); //change divisions and staff numbers alterDivisions( m1, divlcm/div1, 1 ); alterDivisions( m2, divlcm/div2, 2 ); cout << "Adding last backup\n"; //add backup element DOMElement *backupEl = m_doc->createElement(XS("backup")); DOMElement *durEl = m_doc->createElement(XS("duration")); backupEl->appendChild( durEl ); setText(durEl, itoa(divsperbar)); m1->appendChild(backupEl); cout << "Copying children over\n"; //copy children from measure2 into measure1 DOMNodeList *children = m2->getChildNodes(); cout << "No children " << children->getLength() << endl; for( int c=0; c<children->getLength(); c++ ){ cout << c << endl; cout << "No children " << children->getLength() << endl; if( children->item(c)->getNodeType() == DOMNode::ELEMENT_NODE ){ DOMElement *e = (DOMElement*)children->item(c); string tagName = XS(e->getTagName()); //if( tagName == "note" || tagName == "backup" || tagName == "forward" ) if( tagName != "attributes" ) m1->appendChild( ((DOMElement*)children->item(c))->cloneNode(true) ); } } } }
void *NclStructureParser::parseHead( DOMElement *parentElement, void *objGrandParent) { void *parentObject = NULL; DOMNodeList *elementNodeList; int i, size; DOMNode *node; void *elementObject = NULL; parentObject = createHead(parentElement, objGrandParent); if (parentObject == NULL) { return NULL; } elementNodeList = parentElement->getChildNodes(); size = elementNodeList->getLength(); for (i = 0; i < size; i++) { node = elementNodeList->item(i); if (node->getNodeType()==DOMNode::ELEMENT_NODE && XMLString::compareIString( ((DOMElement*)node)->getTagName(), XMLString::transcode("importedDocumentBase")) == 0) { elementObject = getImportParser()-> parseImportedDocumentBase( (DOMElement*)node, parentObject); if (elementObject != NULL) { addImportedDocumentBaseToHead( parentObject, elementObject); break; } } } for (i = 0; i < size; i++) { node = elementNodeList->item(i); if (node->getNodeType()==DOMNode::ELEMENT_NODE && XMLString::compareIString( ((DOMElement*)node)->getTagName(), XMLString::transcode("regionBase") )==0) { elementObject = getLayoutParser()-> parseRegionBase((DOMElement*)node, parentObject); if (elementObject != NULL) { addRegionBaseToHead(parentObject, elementObject); } } } for (i = 0; i < size; i++) { node = elementNodeList->item(i); if (node->getNodeType()==DOMNode::ELEMENT_NODE && XMLString::compareIString( ((DOMElement*)node)->getTagName(), XMLString::transcode("ruleBase") )==0){ elementObject = getPresentationControlParser()-> parseRuleBase((DOMElement*)node, parentObject); if (elementObject != NULL) { addRuleBaseToHead(parentObject, elementObject); break; } } } for (i = 0; i < size; i++) { node = elementNodeList->item(i); if (node->getNodeType()==DOMNode::ELEMENT_NODE && XMLString::compareIString( ((DOMElement*)node)->getTagName(), XMLString::transcode("transitionBase") )==0) { wclog << "NclStructureParser::parseHead "; wclog << "transitionBase i = '" << i << "'" << endl; elementObject = getTransitionParser()-> parseTransitionBase((DOMElement*)node, parentObject); if (elementObject != NULL) { addTransitionBaseToHead(parentObject, elementObject); break; } } } for (i = 0; i < size; i++) { node = elementNodeList->item(i); if (node->getNodeType()==DOMNode::ELEMENT_NODE && XMLString::compareIString( ((DOMElement*)node)->getTagName(), XMLString::transcode("descriptorBase") )==0) { elementObject = getPresentationSpecificationParser()-> parseDescriptorBase((DOMElement*)node, parentObject); if (elementObject != NULL) { addDescriptorBaseToHead(parentObject, elementObject); break; } } } for (i = 0; i < size; i++) { node = elementNodeList->item(i); if (node->getNodeType()==DOMNode::ELEMENT_NODE && XMLString::compareIString( ((DOMElement*)node)->getTagName(), XMLString::transcode("connectorBase") )==0) { elementObject = getConnectorsParser()->parseConnectorBase( (DOMElement*)node, parentObject); if (elementObject != NULL) { addConnectorBaseToHead(parentObject, elementObject); break; } } } for (i = 0; i < size; i++) { node = elementNodeList->item(i); if (node->getNodeType()==DOMNode::ELEMENT_NODE && XMLString::compareIString( ((DOMElement*)node)->getTagName(), XMLString::transcode("meta") )==0) { elementObject = getMetainformationParser()-> parseMeta((DOMElement*)node, parentObject); if (elementObject != NULL) { addMetaToHead(parentObject, elementObject); break; } } } for (i = 0; i < size; i++) { node = elementNodeList->item(i); if (node->getNodeType()==DOMNode::ELEMENT_NODE && XMLString::compareIString( ((DOMElement*)node)->getTagName(), XMLString::transcode("metadata") )==0) { elementObject = getMetainformationParser()-> parseMetadata((DOMElement*)node, parentObject); if (elementObject != NULL) { addMetadataToHead(parentObject, elementObject); break; } } } return parentObject; }
int main(int argc, char ** argv) { // // Initialize the Xerces-c environment // try { XMLPlatformUtils::Initialize(); } catch (const XMLException& toCatch) { fprintf(stderr, "Error during initialization of xerces-c: %s\n", XMLString::transcode(toCatch.getMessage())); return 1; } // // Parse the command line, which should specify exactly one file, which is an // xml file containing the list of test files to be processed. // if (argc != 2) { printf("usage: %s file_name \n" " where file name is the xml file specifying the list of test files.", argv[0]); return 1; } DOMDocument* fileListDoc = parseFile(argv[1]); if (fileListDoc == 0) return 1; // // Iterate over the list of files, running each as a test. // XMLCh tempStr[4000]; XMLString::transcode("testFile", tempStr, 3999); DOMNodeList* list = fileListDoc->getElementsByTagName(tempStr); int i; int numFiles = list->getLength(); for (i=0; i<numFiles; i++) { ++gTestsRun; DOMNode* tmpNode3 = list->item(i); XMLString::transcode("name", tempStr, 3999); const XMLCh* fileName = ((DOMElement*) tmpNode3)->getAttribute(tempStr); if (processTestFile(fileName) == false) ++gTestsFailed; }; // // We are done. Print out a summary of the results // printf("Encoding Tests Results Summary: \n" " %d encoding tests run.\n" " %d tests passed,\n" " %d tests failed\n", gTestsRun, gTestsRun-gTestsFailed, gTestsFailed); delete parser; parser = 0; return 0; };
EppSecDnsKeyData * EppSecDnsKeyData::fromXML( const DOMNode &root ) { EppSecDnsKeyData * data = new EppSecDnsKeyData(); if( data == null ) { return data; } char *p = null; DOMString value; DOMNodeList* list = root.getChildNodes(); for( unsigned int i = 0; i < list->getLength(); i++ ) { DOMNode* node = list->item(i); DOMString name = node->getLocalName(); if( name.isNull() ) { name = node->getNodeName(); } if( name.isNull() ) { continue; } if( name.substringData(0, 7).equals("secDNS:") ) { name = name.substringData(7, name.length() - 7); } if( name.equals("flags") ) { value = EppUtil::getText(*node); p = value.transcode(); if( p != null ) { uint16_t f = (uint16_t) ::atoi(p); XercesString::Delete(p); data->setFlags( f ); } } else if( name.equals("protocol") ) { value = EppUtil::getText(*node); p = value.transcode(); if( p != null ) { uint8_t proto = (uint8_t) ::atoi(p); XercesString::Delete(p); data->setProtocol( proto ); } } else if( name.equals("alg") ) { value = EppUtil::getText(*node); p = value.transcode(); if( p != null ) { uint8_t a = (uint8_t) ::atoi(p); XercesString::Delete(p); data->setAlgorithm(a); } } else if( name.equals("pubKey") ) { value = EppUtil::getText(*node); if( value.length() > 0 ) { data->setPublicKey(value); } } } return data; }
//------------------------------------------------------------------------ // // processTestFile Given the file name of an encoding test xml file, // run it. // //------------------------------------------------------------------------ static bool processTestFile(const XMLCh* fileName) { // // Send the input file through the parse, create a DOM document for it. // char cFileName[4000]; XMLString::transcode(fileName, cFileName, 3999); DOMDocument* testDoc = parseFile(cFileName); if (testDoc == 0) return false; // parse errors in the source xml. // // Pull the "data" element out of the document. // XMLCh tempStr[4000]; XMLString::transcode("data", tempStr, 3999); DOMNodeList* nl = testDoc->getElementsByTagName(tempStr); if (nl->getLength() != 1) { fprintf(stderr, "Test file \"%s\" must have exactly one \"data\" element.\n", cFileName); return false; }; DOMNode* tmpNode = nl->item(0); DOMElement* data = (DOMElement*) tmpNode; // // Build up a string containing the character data contents of the data element. // DOMNode* child; XMLBuffer elData; for (child=data->getFirstChild(); child != 0; child= child->getNextSibling()) { if (child->getNodeType() == DOMNode::COMMENT_NODE) continue; if (! (child->getNodeType() == DOMNode::TEXT_NODE || child->getNodeType() == DOMNode::CDATA_SECTION_NODE || child->getNodeType() == DOMNode::ENTITY_REFERENCE_NODE)) { fprintf(stderr, "Test file \"%s\": data element contains unexpected children.", cFileName); return false; } elData.append(((DOMCharacterData *)child)->getData()); }; // // Pull the "udata" element out of the document // XMLString::transcode("udata", tempStr, 3999); nl = testDoc->getElementsByTagName(tempStr); if (nl->getLength() != 1) { fprintf(stderr, "Test file \"%s\" must have exactly one \"udata\" element.\n", cFileName); return false; }; DOMNode* tmpNode1 = nl->item(0); DOMElement* udata = (DOMElement*) tmpNode1; // // Build up a string containing the character data contents of the udata element. // This will consist of a whole bunch hex numbers, still in string from // XMLBuffer rawUData; for (child=udata->getFirstChild(); child != 0; child= child->getNextSibling()) { if (child->getNodeType() == DOMNode::COMMENT_NODE) continue; if (! (child->getNodeType() == DOMNode::TEXT_NODE || child->getNodeType() == DOMNode::CDATA_SECTION_NODE || child->getNodeType() == DOMNode::ENTITY_REFERENCE_NODE)) { fprintf(stderr, "Test file \"%s\": udata element contains unexpected children.", cFileName); return false; } rawUData.append(((DOMCharacterData *)child)->getData()); }; // // Convert the raw (hex numbers) form of the udata to the corresponding string. // XMLBuffer uData; unsigned int rawIndex = 0; while (rawIndex < rawUData.getLen()) { eatWhiteSpace(rawUData.getRawBuffer(), rawIndex); XMLCh c = convertHexValue(rawUData.getRawBuffer(), rawIndex); if (c > 0) uData.append(c); else if (rawIndex < rawUData.getLen()) { fprintf(stderr, "Test file \"%s\": Bad hex number in udata element. " "Data character number %d\n", cFileName, uData.getLen()); return false; } } // // Compare the two strings. // unsigned int i; for (i=0; i< elData.getLen(); i++) { XMLCh* elDataRaw = elData.getRawBuffer(); XMLCh* uDataRaw = uData.getRawBuffer(); if (i >= uData.getLen()) { fprintf(stderr, "Test file \"%s\": udata element shorter than data at char number %d\n", cFileName, i); writeUData(elDataRaw); return false; } if (uDataRaw[i] != elDataRaw[i]) { fprintf(stderr, "Test file \"%s\": comparison failure at character number %d\n", cFileName, i); writeUData(elDataRaw); return false; }; } if (elData.getLen() != uData.getLen()) { fprintf(stderr, "Test file \"%s\": udata element longer than data at char number %d\n", cFileName, i); writeUData(elData.getRawBuffer()); return false; } return true; }
void GeomAttributesBuilder::getParameters() { // First set default parameters. // The parameters are dependent on the type of geom // box: length, width, height (all doubles) // ccylinder: radius, length (all doubles) // sphere: radius (all doubles) // plane: normal_x, normal_y, normal_z, d (all doubles) // mesh: filname (std::string) std::string type = attrib_->getValAsStr("type"); if (!type.compare("box")) { attrib_->add("length", "1"); attrib_->add("width", "1"); attrib_->add("height", "1"); } else if (!type.compare("ccylinder")) { attrib_->add("radius", "1"); attrib_->add("length", "3"); } else if (!type.compare("cylinder")) { attrib_->add("radius", "1"); attrib_->add("length", "3"); } else if (!type.compare("sphere")) { attrib_->add("radius", "1"); } else if (!type.compare("plane")) { attrib_->add("normal_x", "0"); attrib_->add("normal_y", "0"); attrib_->add("normal_z", "1"); attrib_->add("d", "0"); } else if (!type.compare("mesh")) { attrib_->add("filename", "_NODATA_"); } else { return; } DOMNodeList* allChildNodes = node_->getChildNodes(); // Loop over all of the parameters for (unsigned int c = 0; c < allChildNodes->getLength(); ++c) { DOMNode* thisChildItem = allChildNodes->item(c); if (thisChildItem->getNodeType() == DOMNode::ELEMENT_NODE) { char* pChildTagName = XMLString::transcode(thisChildItem->getNodeName()); if ( strcmp(pChildTagName, "parameter") == 0 ) { if ( thisChildItem->hasAttributes() ) { DOMNamedNodeMap* theAttributes = thisChildItem->getAttributes(); int numAttributes = theAttributes->getLength(); if (numAttributes == 2) { // Parameters can only 1 Name/Value pair DOMNode* nodeName = theAttributes->item(0); DOMNode* nodeValue = theAttributes->item(1); const XMLCh* xmlch_Name = nodeName->getNodeValue(); char* attrName = XMLString::transcode(xmlch_Name); const XMLCh* xmlch_Value = nodeValue->getNodeValue(); char* attrValue = XMLString::transcode(xmlch_Value); try { attrib_->update(attrName, attrValue); } catch (std::runtime_error &ex) { std::cerr << ex.what() << std::endl << builderType_ << "::getParameters() - " << "In geom \"" << attrib_->getValAsStr("name") << "\", parameter \"" << attrName << "=" << attrValue << "\" is illegal for this geom type (" << attrib_->getValAsStr("type") << "). Ignoring it." << std::endl; }; XMLString::release( &attrName ); XMLString::release( &attrValue ); } } } delete [] pChildTagName; } } }
void SpaceAttributesBuilder::getParameters() { // First set default parameters. // The parameters are dependent on the type of space // simple: No parameters // hash: center, dVector3 // extents, dVector3 // depth, int // quatree: minlevel, int // maxlevel, int std::string type = attrib_->getValAsStr("type"); if (!type.compare("simple")) return; // No parameters for simple space else if (!type.compare("hash")) { attrib_->add("center", "0 0 0"); attrib_->add("extents", "0 0 0"); attrib_->add("depth", "4"); } else if (!type.compare("quadtree")) { attrib_->add("minlevel", "-1"); attrib_->add("maxlevel", "8"); } else { return; } DOMNodeList* allChildNodes = node_->getChildNodes(); // Loop over all of the spaces for (unsigned int c = 0; c < allChildNodes->getLength(); ++c) { DOMNode* thisChildItem = allChildNodes->item(c); if (thisChildItem->getNodeType() == DOMNode::ELEMENT_NODE) { char* pChildTagName = XMLString::transcode(thisChildItem->getNodeName()); if ( strcmp(pChildTagName, "parameter") == 0 ) { if ( thisChildItem->hasAttributes() ) { DOMNamedNodeMap* theAttributes = thisChildItem->getAttributes(); int numAttributes = theAttributes->getLength(); if (numAttributes == 2) { DOMNode* nodeName = theAttributes->item(0); DOMNode* nodeValue = theAttributes->item(1); const XMLCh* xmlch_Name = nodeName->getNodeValue(); char* attrName = XMLString::transcode(xmlch_Name); const XMLCh* xmlch_Value = nodeValue->getNodeValue(); char* attrValue = XMLString::transcode(xmlch_Value); try { attrib_->update(attrName, attrValue); } catch (std::runtime_error &ex) { std::cerr << ex.what() << std::endl << builderType_ << "::getParameters() - " << "In space \"" << attrib_->getValAsStr("name") << "\", parameter \"" << attrName << "=" << attrValue << "\" is illegal for this space type (" << attrib_->getValAsStr("type") << "). Ignoring it." << std::endl; } XMLString::release( &attrName ); XMLString::release( &attrValue ); } } } delete [] pChildTagName; } } }
/** * Canonicalize XML node using one of the supported methods in XML-DSIG * Using Xerces for parsing XML to preserve the white spaces "as is" and get * the same digest value on XML node each time. * * @param calc digest calculator implementation. * @param ns signature tag namespace. * @param tagName signature tag name. */ void SignatureBES::calcDigestOnNode(Digest* calc, const string& ns, const string& tagName, const string &id) const { try { // Parse Xerces DOM from file, to preserve the white spaces "as is" // and get the same digest value on XML node. // Canonical XML 1.0 specification (http://www.w3.org/TR/2001/REC-xml-c14n-20010315) // needs all the white spaces from XML file "as is", otherwise the digests won't match. // Therefore we have to use Xerces to parse the XML file each time a digest needs to be // calculated on a XML node. If you are parsing XML files with a parser that doesn't // preserve the white spaces you are DOOMED! // Initialize Xerces parser. unique_ptr<XercesDOMParser> parser(new XercesDOMParser()); parser->setDoNamespaces(true); parser->setValidationScheme(XercesDOMParser::Val_Always); parser->setDoSchema(true); parser->setCreateEntityReferenceNodes(false); //ErrorHandler* errorHandler = /*(ErrorHandler*)*/ new HandlerBase(); //parser->setErrorHandler(errorHandler); // Parse and return a copy of the Xerces DOM tree. // Save to file an parse it again, to make XML Canonicalization work // correctly as expected by the Canonical XML 1.0 specification. // Hope, the next Canonical XMl specification fixes the white spaces preserving "bug". stringstream ofs; saveToXml(ofs); string data = ofs.str(); MemBufInputSource source((XMLByte*)data.c_str(), data.size(), "temp"); parser->parse(source); DOMDocument *dom = parser->getDocument(); DOMNode *node = nullptr; // Select node, on which the digest is calculated. if(id.empty()) { XMLCh *tagNs = XMLString::transcode(ns.c_str()); XMLCh *tag = XMLString::transcode(tagName.c_str()); DOMNodeList* nodeList = dom->getElementsByTagNameNS(tagNs, tag); if(nodeList->getLength() == 1) node = nodeList->item(0); XMLString::release(&tagNs); XMLString::release(&tag); } else { XMLCh *tagId = XMLString::transcode(id.c_str()); node = dom->getElementById(tagId); XMLString::release(&tagId); } // Make sure that exactly one node was found. if(!node) THROW("Could not find '%s' node which is in '%s' namespace in signature XML.", tagName.c_str(), ns.c_str()); // Canocalize XML using one of the three methods supported by XML-DSIG XSECC14n20010315 canonicalizer(dom, node); canonicalizer.setCommentsProcessing(false); canonicalizer.setUseNamespaceStack(true); // Find the method identifier SignedInfoType& signedInfo = signature->signedInfo(); CanonicalizationMethodType& canonMethod = signedInfo.canonicalizationMethod(); CanonicalizationMethodType::AlgorithmType& algorithmType = canonMethod.algorithm(); DEBUG("C14N ns(%s) tagName(%s) algorithmType(%s)", ns.c_str(), tagName.c_str(), algorithmType.c_str()); // Set processing flags according to algorithm type. if(algorithmType == URI_ID_C14N_NOC) { // Default behaviour, nothing needs to be changed } else if(algorithmType == URI_ID_C14N_COM) { canonicalizer.setCommentsProcessing(true); } else if(algorithmType == URI_ID_EXC_C14N_NOC) { // Exclusive mode needs to include xml-dsig in root element // in order to maintain compatibility with existing implementations canonicalizer.setExclusive(); } else if(algorithmType == URI_ID_EXC_C14N_COM) { canonicalizer.setExclusive(); canonicalizer.setCommentsProcessing(true); } else if(algorithmType == URI_ID_C14N11_NOC) { canonicalizer.setInclusive11(); } else if(algorithmType == URI_ID_C14N11_COM) { canonicalizer.setInclusive11(); canonicalizer.setCommentsProcessing(true); } else { // Unknown algorithm. THROW("Unsupported SignedInfo canonicalization method '%s'", algorithmType.c_str()); } string c14n; unsigned char buffer[1024]; xsecsize_t bytes = 0; while((bytes = canonicalizer.outputBuffer(buffer, 1024)) > 0) { calc->update(buffer, (unsigned int)bytes); c14n.append( (char*)&buffer[0], size_t(bytes)); } //DEBUG("c14n = \n%s", c14n.c_str()); } catch(const Exception& e) { THROW_CAUSE(e, "Failed to create Xerces DOM from signature XML."); } catch(const XMLException& e) { ArrayJanitor<char> msg(XMLString::transcode(e.getMessage())); THROW( "Failed to parse signature XML: %s", msg.get() ); } catch(const DOMException& e) { ArrayJanitor<char> msg(XMLString::transcode(e.getMessage())); THROW( "Failed to parse signature XML: %s", msg.get() ); } catch(...) { THROW("Failed to parse signature XML."); } }
void FDPLoader::loadFDPItem(DOMNode* pFDPItem) { DOMNamedNodeMap* attrList = pFDPItem->getAttributes(); FDPItem* pItem = 0; // get the name (id) DOMNode* attr = attrList->getNamedItem(XercesString("name")); if(attr) { char* name = XMLString::transcode(attr->getNodeValue()); // create a new item (will be deleted in dtor of FDP class) pItem = new FDPItem(name); XMLString::release(&name); } else return; // get the control vertex index attr = attrList->getNamedItem(XercesString("index")); if(attr) { char* index = XMLString::transcode(attr->getNodeValue()); pItem->setControlPoint((unsigned short)atoi(index)); XMLString::release(&index); } // get the affecting mesh name attr = attrList->getNamedItem(XercesString("affects")); if(attr) { char* affects = XMLString::transcode(attr->getNodeValue()); pItem->setAffects(affects); XMLString::release(&affects); } DOMNodeIterator* iterator = m_pDoc->createNodeIterator(pFDPItem, DOMNodeFilter::SHOW_ELEMENT | DOMNodeFilter::SHOW_ATTRIBUTE, NULL, true); // use the tree walker to print out the text nodes. for ( DOMNode* current = iterator->nextNode(); current != 0; current = iterator->nextNode() ) { if(XercesString(current->getNodeName()) == "indices") { DOMNodeList* children = current->getChildNodes(); // we should have only one child, text node, just a safety net here if ( (children->getLength() == 1) && (children->item(0)->getNodeType() == DOMNode::TEXT_NODE) )//(XercesString(children->item(0)->getNodeName()) == "#text") ) { char* pStr = XMLString::transcode(children->item(0)->getNodeValue()); std::string str(pStr); processIndices(str, pItem); XMLString::release(&pStr); } } else if (XercesString(current->getNodeName()) == "influence") // can have multiple of those { // sample: <influence weight="0.25" fap="3" type="RaisedCosInfluenceWaveY" /> DOMNamedNodeMap* influenceAttr = current->getAttributes(); // get the weight float w = toFloat(influenceAttr->getNamedItem(XercesString("weight"))->getNodeValue()); unsigned short fap = (unsigned short)toFloat(influenceAttr->getNamedItem(XercesString("fap"))->getNodeValue()); char* typeTmp = XMLString::transcode(influenceAttr->getNamedItem(XercesString("type"))->getNodeValue()); std::string type; type.assign(typeTmp); XMLString::release(&typeTmp); IInfluenceCalculator* pInfluence = InfluenceCalculatorMaker::newInfluenceCalculator(type, w, fap); if(pInfluence) pItem->addInfluenceCalculator(pInfluence); } } m_pFDP->insertItem(pItem); }