bool XMLFileParser::Read(XMLContainer & container, DirectoryMode mode) { pugi::xml_document XMLDocument; pugi::xml_parse_result result; SerializedData data; data.data = ReadBinaryFile(m_File.GetLocalPath(), data.size, mode); result = XMLDocument.load_buffer_inplace_own(data.data, data.size); Logger::GetInstance()->Log(result, star::string_cast<tstring>(result.description()), STARENGINE_LOG_TAG); if (result) { auto root = XMLDocument.first_child(); if(root != NULL) { container.SetName(star::string_cast<tstring>(root.name())); AddAttributes(container, root); auto child = root.first_child(); if(child != NULL) { do { AddChild(container, child); child = child.next_sibling(); } while (child != NULL); } } } return result; }
nsresult XULContentSinkImpl::OpenRoot(const PRUnichar** aAttributes, const PRUint32 aAttrLen, nsINodeInfo *aNodeInfo) { NS_ASSERTION(mState == eInProlog, "how'd we get here?"); if (mState != eInProlog) return NS_ERROR_UNEXPECTED; nsresult rv; if (aNodeInfo->Equals(nsGkAtoms::script, kNameSpaceID_XHTML) || aNodeInfo->Equals(nsGkAtoms::script, kNameSpaceID_XUL)) { PR_LOG(gLog, PR_LOG_ERROR, ("xul: script tag not allowed as root content element")); return NS_ERROR_UNEXPECTED; } // Create the element nsXULPrototypeElement* element; rv = CreateElement(aNodeInfo, &element); if (NS_FAILED(rv)) { #ifdef PR_LOGGING if (PR_LOG_TEST(gLog, PR_LOG_ERROR)) { nsAutoString anodeC; aNodeInfo->GetName(anodeC); PR_LOG(gLog, PR_LOG_ERROR, ("xul: unable to create element '%s' at line %d", NS_ConvertUTF16toUTF8(anodeC).get(), -1)); // XXX pass in line number } #endif return rv; } // Set the correct script-type for the element. rv = SetElementScriptType(element, aAttributes, aAttrLen); if (NS_FAILED(rv)) return rv; // Push the element onto the context stack, so that child // containers will hook up to us as their parent. rv = mContextStack.Push(element, mState); if (NS_FAILED(rv)) { element->Release(); return rv; } // Add the attributes rv = AddAttributes(aAttributes, aAttrLen, element); if (NS_FAILED(rv)) return rv; mState = eInDocumentElement; return NS_OK; }
ALERROR CTopologyNode::InitFromAttributesXML (CXMLElement *pAttributes, CString *retsError) // InitFromAttributesXML // // Adds attributes { AddAttributes(pAttributes->GetAttribute(ATTRIBUTES_ATTRIB)); return NOERROR; }
void VertexArray::Init(const TriangleMesh *mesh) { const int ctVertices = mesh->mPositions.size(); const int ctIndices = mesh->mIndices.size(); AddAttributes(mesh->GetVertexAttribDefs()); Init(ctVertices, ctVertices); SetVertices(static_cast<const GLvoid*>(mesh->GetVertexArray().data()), 0, ctVertices); if(ctIndices > 0) { void *indices = mesh->GetIndices(); SetIndices(indices, ctIndices, mesh->GetIndexType()); delete[] indices; } }
void XMLFileParser::AddChild(XMLContainer & parent, const pugi::xml_node & node) { std::shared_ptr<XMLContainer> child(new XMLContainer()); AddAttributes(*(child.get()), node); child->SetName(star::string_cast<tstring>(node.name())); child->SetValue(star::string_cast<tstring>(node.child_value())); auto sibling = node.first_child(); if(sibling != NULL) { do { AddChild(*(child.get()), sibling); sibling = sibling.next_sibling(); } while (sibling != NULL); } if(child->GetName() != EMPTY_STRING) { parent.insert(std::make_pair(star::string_cast<tstring>(node.name()), child)); } }
nsresult XULContentSinkImpl::OpenTag(const PRUnichar** aAttributes, const PRUint32 aAttrLen, const PRUint32 aLineNumber, nsINodeInfo *aNodeInfo) { nsresult rv; // Create the element nsXULPrototypeElement* element; rv = CreateElement(aNodeInfo, &element); if (NS_FAILED(rv)) { #ifdef PR_LOGGING if (PR_LOG_TEST(gLog, PR_LOG_ERROR)) { nsAutoString anodeC; aNodeInfo->GetName(anodeC); PR_LOG(gLog, PR_LOG_ERROR, ("xul: unable to create element '%s' at line %d", NS_ConvertUTF16toUTF8(anodeC).get(), aLineNumber)); } #endif return rv; } // Link this element to its parent. nsPrototypeArray* children = nsnull; rv = mContextStack.GetTopChildren(&children); if (NS_FAILED(rv)) { delete element; return rv; } // Add the attributes rv = AddAttributes(aAttributes, aAttrLen, element); if (NS_FAILED(rv)) return rv; children->AppendElement(element); if (aNodeInfo->Equals(nsGkAtoms::script, kNameSpaceID_XHTML) || aNodeInfo->Equals(nsGkAtoms::script, kNameSpaceID_XUL)) { // Do scripty things now rv = OpenScript(aAttributes, aLineNumber); NS_ENSURE_SUCCESS(rv, rv); NS_ASSERTION(mState == eInScript || mState == eInDocumentElement, "Unexpected state"); if (mState == eInScript) { // OpenScript has pushed the nsPrototypeScriptElement onto the // stack, so we're done. return NS_OK; } } // Push the element onto the context stack, so that child // containers will hook up to us as their parent. rv = mContextStack.Push(element, mState); if (NS_FAILED(rv)) return rv; mState = eInDocumentElement; return NS_OK; }
ALERROR CTopologyNode::InitFromSystemXML (CXMLElement *pSystem, CString *retsError) // InitFromSystemXML // // Initializes the system information based on an XML element. // NOTE: We assume the universe is fully bound at this point. { ALERROR error; CString sSystemUNID = pSystem->GetAttribute(UNID_ATTRIB); DWORD dwUNID = strToInt(sSystemUNID, 0, NULL); // If the system node contains a table of different system types, then // remember the root node because some of the system information (such as the // name) may be there. CXMLElement *pSystemParent = NULL; // If there is no UNID attribute then it means that the system // is randomly determined based on a table if (dwUNID == 0 && pSystem->GetContentElementCount() == 1) { CXMLElement *pTableElement = pSystem->GetContentElement(0); if (pTableElement == NULL) { ASSERT(false); return ERR_FAIL; } CRandomEntryResults System; if (error = CRandomEntryGenerator::Generate(pTableElement, System)) { *retsError = strPatternSubst(CONSTLIT("Topology %s: Unable to generate random system UNID"), m_sID); return ERR_FAIL; } if (System.GetCount() != 1) { *retsError = strPatternSubst(CONSTLIT("Topology %s: Table generated no systems"), m_sID); return ERR_FAIL; } pSystemParent = pSystem; pSystem = System.GetResult(0); dwUNID = pSystem->GetAttributeInteger(UNID_ATTRIB); } // Set the system UNID if (dwUNID != 0) m_SystemUNID = dwUNID; // Get the system type CSystemType *pSystemType = g_pUniverse->FindSystemType(m_SystemUNID); // Set the name of the system CString sName; if (!pSystem->FindAttribute(NAME_ATTRIB, &sName)) if (pSystemParent) sName = pSystemParent->GetAttribute(NAME_ATTRIB); if (!sName.IsBlank()) SetName(sName); // Set the level int iLevel = 0; if (!pSystem->FindAttributeInteger(LEVEL_ATTRIB, &iLevel)) if (pSystemParent) iLevel = pSystemParent->GetAttributeInteger(LEVEL_ATTRIB); if (iLevel > 0) SetLevel(iLevel); if (GetLevel() == 0) SetLevel(1); // Add variants for the system CString sVariant; if (pSystem->FindAttribute(VARIANT_ATTRIB, &sVariant)) AddVariantLabel(sVariant); if (pSystemParent && pSystemParent->FindAttribute(VARIANT_ATTRIB, &sVariant)) AddVariantLabel(sVariant); // Add attributes for the node/system CString sAttribs; if (pSystem->FindAttribute(ATTRIBUTES_ATTRIB, &sAttribs)) AddAttributes(sAttribs); if (pSystemParent && pSystemParent->FindAttribute(ATTRIBUTES_ATTRIB, &sAttribs)) AddAttributes(sAttribs); if (pSystemType && !pSystemType->GetAttributes().IsBlank()) AddAttributes(pSystemType->GetAttributes()); return NOERROR; }
BOOL FreeHandEPSFilter::AddNewNode(Node *pNewNode) { if(IS_A(pNewNode, NodePath)) pLastPathSeen = (NodePath *)pNewNode; // check to see if we want to handle this if((ComplexPathMode == FALSE) || (pNewNode == 0) || (pNode == 0) || (!IS_A(pNewNode, NodePath))) return EPSFilter::AddNewNode(pNewNode); // check to see if this is the first... if(HadFirstOfComplexPath == FALSE) { HadFirstOfComplexPath = TRUE; return EPSFilter::AddNewNode(pNewNode); } // find the last child of the node Node *pLastChild = pNode->FindLastChild(); if(pLastChild == 0 || !IS_A(pLastChild, NodePath)) return EPSFilter::AddNewNode(pNewNode); // we know that both of these things are NodePaths. Path *pTarget = &((NodePath *)pLastChild)->InkPath; Path *pAddition = &((NodePath *)pNewNode)->InkPath; // work out the new flags for the target BOOL TargetFilled = pTarget->IsFilled; BOOL TargetStroked = pTarget->IsStroked; if(pAddition->IsFilled) TargetFilled = TRUE; if(pAddition->IsStroked) TargetStroked = TRUE; // add this new path to the old one... if(!pTarget->MergeTwoPaths(*pAddition)) return FALSE; // check that the thing we just added isn't already there if(!RemoveLastSubPathIfNotUnique(pTarget)) return FALSE; // set it's flags pTarget->IsFilled = TargetFilled; pTarget->IsStroked = TargetStroked; // vape it's attributes pLastChild->DeleteChildren(pLastChild->FindFirstChild()); // apply some new ones SetPathFilled(TargetFilled); if(!AddAttributes((NodePath *)pLastChild, TargetStroked, TargetFilled)) return FALSE; // hide the nice additional path //if(!ImportInfo.pOp->DoHideNode(pNewNode, TRUE)) // return FALSE; pNewNode->CascadeDelete(); delete pNewNode; // set the last seen path bollox pLastPathSeen = (NodePath *)pLastChild; // done! return TRUE; }
OGRErr GMLHandler::startElementGeometry(const char *pszName, int nLenName, void* attr ) { if( nLenName == 9 && strcmp(pszName, "boundedBy") == 0 ) { m_inBoundedByDepth = m_nDepth; PUSH_STATE(STATE_BOUNDED_BY); return OGRERR_NONE; } /* Create new XML Element */ CPLXMLNode* psCurNode = (CPLXMLNode *) CPLCalloc(sizeof(CPLXMLNode),1); psCurNode->eType = CXT_Element; psCurNode->pszValue = (char*) CPLMalloc( nLenName+1 ); memcpy(psCurNode->pszValue, pszName, nLenName+1); /* Attach element as the last child of its parent */ NodeLastChild& sNodeLastChild = apsXMLNode[apsXMLNode.size()-1]; CPLXMLNode* psLastChildParent = sNodeLastChild.psLastChild; if (psLastChildParent == NULL) { CPLXMLNode* psParent = sNodeLastChild.psNode; if (psParent) psParent->psChild = psCurNode; } else { psLastChildParent->psNext = psCurNode; } sNodeLastChild.psLastChild = psCurNode; /* Add attributes to the element */ CPLXMLNode* psLastChildCurNode = AddAttributes(psCurNode, attr); /* Some CityGML lack a srsDimension="3" in posList, such as in */ /* http://www.citygml.org/fileadmin/count.php?f=fileadmin%2Fcitygml%2Fdocs%2FFrankfurt_Street_Setting_LOD3.zip */ /* So we have to add it manually */ if (m_bIsCityGML && nLenName == 7 && strcmp(pszName, "posList") == 0 && CPLGetXMLValue(psCurNode, "srsDimension", NULL) == NULL) { CPLXMLNode* psChild = CPLCreateXMLNode(NULL, CXT_Attribute, "srsDimension"); CPLCreateXMLNode(psChild, CXT_Text, "3"); if (psLastChildCurNode == NULL) psCurNode->psChild = psChild; else psLastChildCurNode->psNext = psChild; psLastChildCurNode = psChild; } /* Push the element on the stack */ NodeLastChild sNewNodeLastChild; sNewNodeLastChild.psNode = psCurNode; sNewNodeLastChild.psLastChild = psLastChildCurNode; apsXMLNode.push_back(sNewNodeLastChild); if (m_pszGeometry) { CPLFree(m_pszGeometry); m_pszGeometry = NULL; m_nGeomAlloc = 0; m_nGeomLen = 0; } return OGRERR_NONE; }