void DeltaApplyEngine::TextNode_Update( XID_t nodeXID, DOMNode *operationNode ) { vddprintf((" update xid=%d\n",(int)nodeXID)); DOMNode* upNode = xiddoc->getXidMap().getNodeWithXID( nodeXID ); if (upNode==NULL) THROW_AWAY(("node with XID=%d not found",(int)nodeXID)); DOMNodeList *opNodes = operationNode->getChildNodes(); vddprintf(("opNodes->length() = %d\n", opNodes->getLength())); XyStrDeltaApply *xytext = new XyStrDeltaApply(xiddoc, upNode, 1); xytext->setApplyAnnotations(applyAnnotations); for (int i = opNodes->getLength() - 1; i >= 0; i--) { DOMElement *op = (DOMElement *) opNodes->item(i); char *optype = XMLString::transcode(op->getLocalName()); XMLCh pos_attr[4]; XMLCh len_attr[4]; XMLString::transcode("pos", pos_attr, 3); XMLString::transcode("len", len_attr, 3); vddprintf(("item %d = %s\n", i, optype)); // Replace operation if (strcmp(optype, "tr") == 0) { char *pos = XMLString::transcode(op->getAttribute(pos_attr)); char *len = XMLString::transcode(op->getAttribute(len_attr)); xytext->replace(atoi(pos), atoi(len), op->getTextContent()); XMLString::release(&pos); XMLString::release(&len); } // Delete operation else if (strcmp(optype, "td") == 0) { char *pos = XMLString::transcode(op->getAttribute(pos_attr)); char *len = XMLString::transcode(op->getAttribute(len_attr)); xytext->remove(atoi(pos), atoi(len)); XMLString::release(&pos); XMLString::release(&len); } // Insert operation else if (strcmp(optype, "ti") == 0) { char *pos = XMLString::transcode(op->getAttribute(pos_attr)); xytext->insert(atoi(pos), op->getTextContent()); XMLString::release(&pos); } XMLString::release(&optype); } xytext->complete(); delete xytext; }
musicxml::score_timewise musicxml::parse<musicxml::score_timewise>(std::istream &is, const std::string &id) { xml::auto_initializer xerces_platform { true, false }; std::unique_ptr<DOMDocument> doc { dom_document(is, id, true) }; DOMElement *root { doc->getDocumentElement() }; std::string const ns { xml::transcode<char>(root->getNamespaceURI()) }; std::string const name { xml::transcode<char>(root->getLocalName()) }; if (ns == "") { if (name == "score-partwise") { return musicxml::convert(musicxml::score_partwise{*root}); } else if (name == "score-timewise") { return musicxml::score_timewise{*root}; } } throw tree::unexpected_element<char>(name, ns, "score-partwise|score-timewise", ""); }
DOMElement* SchemaInfo::getTopLevelComponent(const unsigned short compCategory, const XMLCh* const compName, const XMLCh* const name) { if (compCategory >= C_Count) return 0; DOMElement* child = XUtil::getFirstChildElement(fSchemaRootElement); if (!child) return 0; RefHashTableOf<DOMElement>* compList = fTopLevelComponents[compCategory]; if (fTopLevelComponents[compCategory] == 0) { compList= new (fMemoryManager) RefHashTableOf<DOMElement>(17, false, fMemoryManager); fTopLevelComponents[compCategory] = compList; } else { DOMElement* cachedChild = compList->get(name); if(cachedChild) return cachedChild; child = fLastTopLevelComponent[compCategory]; } DOMElement* redefParent = (DOMElement*) child->getParentNode(); // Parent is not "redefine" if (!XMLString::equals(redefParent->getLocalName(),SchemaSymbols::fgELT_REDEFINE)) redefParent = 0; while (child != 0) { fLastTopLevelComponent[compCategory]=child; if (XMLString::equals(child->getLocalName(), compName)) { const XMLCh* cName=child->getAttribute(SchemaSymbols::fgATT_NAME); compList->put((void*)cName, child); if (XMLString::equals(cName, name)) return child; } else if (XMLString::equals(child->getLocalName(),SchemaSymbols::fgELT_REDEFINE) && (!fFailedRedefineList || !fFailedRedefineList->containsElement(child))) { // if redefine DOMElement* redefineChild = XUtil::getFirstChildElement(child); while (redefineChild != 0) { fLastTopLevelComponent[compCategory]=redefineChild; if ((!fFailedRedefineList || !fFailedRedefineList->containsElement(redefineChild)) && XMLString::equals(redefineChild->getLocalName(), compName)) { const XMLCh* rName=redefineChild->getAttribute(SchemaSymbols::fgATT_NAME); compList->put((void*)rName, redefineChild); if (XMLString::equals(rName, name)) return redefineChild; } redefineChild = XUtil::getNextSiblingElement(redefineChild); } } child = XUtil::getNextSiblingElement(child); if (child == 0 && redefParent) { child = XUtil::getNextSiblingElement(redefParent); redefParent = 0; } } return child; }
DOMElement* SchemaInfo::getTopLevelComponent(const unsigned short compCategory, const XMLCh* const compName, const XMLCh* const name) { if (compCategory >= C_Count) return 0; DOMElement* child = XUtil::getFirstChildElement(fSchemaRootElement); if (!child) return 0; ValueVectorOf<DOMElement*>* compList = fTopLevelComponents[compCategory]; if (fTopLevelComponents[compCategory] == 0) { compList= new (fMemoryManager) ValueVectorOf<DOMElement*>(16, fMemoryManager); fTopLevelComponents[compCategory] = compList; } else { unsigned int listLen = compList->size(); for (unsigned int i= 0; i < listLen; i++) { child = compList->elementAt(i); if (XMLString::equals(child->getAttribute(SchemaSymbols::fgATT_NAME), name)) return child; } } DOMElement* redefParent = (DOMElement*) child->getParentNode(); // Parent is not "redefine" if (!XMLString::equals(redefParent->getLocalName(),SchemaSymbols::fgELT_REDEFINE)) redefParent = 0; while (child != 0) { if (XMLString::equals(child->getLocalName(), compName)) { compList->addElement(child); if (XMLString::equals(child->getAttribute(SchemaSymbols::fgATT_NAME), name)) return child; } else if (XMLString::equals(child->getLocalName(),SchemaSymbols::fgELT_REDEFINE) && (!fFailedRedefineList || !fFailedRedefineList->containsElement(child))) { // if redefine DOMElement* redefineChild = XUtil::getFirstChildElement(child); while (redefineChild != 0) { if ((!fFailedRedefineList || !fFailedRedefineList->containsElement(redefineChild)) && XMLString::equals(redefineChild->getLocalName(), compName)) { compList->addElement(redefineChild); if (XMLString::equals(redefineChild->getAttribute(SchemaSymbols::fgATT_NAME), name)) return redefineChild; } redefineChild = XUtil::getNextSiblingElement(redefineChild); } } child = XUtil::getNextSiblingElement(child); if (child == 0 && redefParent) { child = XUtil::getNextSiblingElement(redefParent); redefParent = 0; } } return child; }