本文整理汇总了C++中DOMElement::getNodeName方法的典型用法代码示例。如果您正苦于以下问题:C++ DOMElement::getNodeName方法的具体用法?C++ DOMElement::getNodeName怎么用?C++ DOMElement::getNodeName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMElement
的用法示例。
在下文中一共展示了DOMElement::getNodeName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readFile
void Parameters::readFile(string str){
file = str;
XMLPlatformUtils::Initialize();
XercesDOMParser parser;
parser.setValidationScheme(XercesDOMParser::Val_Always);
HandlerBase errHandler;// = (ErrorHandler*) new HandlerBase();
parser.setErrorHandler(&errHandler);
parser.parse(str.c_str());
DOMDocument * doc = parser.getDocument();
DOMElement* elementRoot = doc->getDocumentElement();
// Extract floats
DOMElement* floatRoot = (DOMElement *)
elementRoot->getElementsByTagName(XMLString::transcode("real"))->item(0);
DOMElement* child = floatRoot->getFirstElementChild();
do{
saveReal(XMLString::transcode(child->getNodeName()),
atof(XMLString::transcode(child->getTextContent())));
child = child->getNextElementSibling();
}while(child != NULL);
// Extract integers
DOMElement* intRoot = (DOMElement *)
elementRoot->getElementsByTagName(XMLString::transcode("integer"))->item(0);
child = intRoot->getFirstElementChild();
do{
saveInteger(
XMLString::transcode(child->getNodeName()),
atoi(XMLString::transcode(child->getTextContent())));
child = child->getNextElementSibling();
}while(child != NULL);
}
示例2: LoadProgram
ret_ CXMLLoaderActions::LoadProgram(const CData *pParentData,
CProgram &Program,
const DOMElement *pElement,
const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
if (!pParentData)
return PARAMETER_NULL | PARAMETER_1;
if (!pElement)
return PARAMETER_NULL | PARAMETER_3;
#endif
auto_xerces_str wsDataBlock("data_block");
auto_xerces_str wsProcessBlock("process_block");
DOMElement *pChild = (DOMElement *)pElement->getFirstChild();
if (!pChild)
return XML_LOADER_ERROR;
Program.Data().SetParent(pParentData);
while (pChild)
{
if (0 == XMLString::compareString(pChild->getNodeName(),
wsDataBlock))
{
CData Data;
if (SUCCESS != (LoadDataBlock(Data, pChild)))
return XML_LOADER_ERROR;
Program.SetData(Data);
}
else if (0 == XMLString::compareString(pChild->getNodeName(),
wsProcessBlock))
{
if (SUCCESS != LoadProcessBlock(Program, pChild, pPDU))
return XML_LOADER_ERROR;
}
pChild = (DOMElement *)pChild->getNextSibling();
}
return SUCCESS;
}
示例3: processNode
/*****************************************************
* XmlWorldParser implementation
***************************************************/
void XmlWorldParser::processNode(DOMTreeWalker* tw, const double* pos) {
do {
DOMElement* node = (DOMElement*) tw->getCurrentNode();
// printNode(node);
/* Process body */
if (XMLString::equals(XMLString::transcode("body"), node->getNodeName())) {
cout << "adding a body" << endl;
addBody(node, pos);
} else
/* Process joint */
if (XMLString::equals(XMLString::transcode("joint"),
node->getNodeName())) {
addJoint(node, pos);
} else
/* Process a transform */
if (XMLString::equals(XMLString::transcode("transform"),
node->getNodeName())) {
double trans[3];
char* x_c = getAttribute(node, "x");
char* y_c = getAttribute(node, "y");
char* z_c = getAttribute(node, "z");
if (x_c == NULL || y_c == NULL || z_c == NULL)
throw exception();
trans[0] = pos[0] + atof(x_c);
trans[1] = pos[1] + atof(y_c);
trans[2] = pos[2] + atof(z_c);
if (tw->firstChild() != NULL) {
processNode(tw, trans);
}
} else if (tw->firstChild() != NULL) {
processNode(tw, pos);
}
} while (tw->nextSibling() != NULL);
tw->parentNode();
return;
}
示例4:
const char *SkinElementsMgr::getElementAlias(const char *id) {
if(m_doc) {
DOMElement * node = m_doc->getElementById(id);
if (node && !STRCMP(node->getNodeName(),"elementalias")) {
DOMAttr * attr = node->getAttributeNode("target");
if( attr && attr->getSpecified() )
return attr->getValue();
}
}
return NULL;
}
示例5: xml
vector<ImportDescriptor*> LayerImporter::getImportDescriptors(const string& filename, bool reportErrors)
{
vector<ImportDescriptor*> descriptors;
if (!filename.empty())
{
MessageLog* pLog = NULL;
if (reportErrors == true)
{
Service<MessageLogMgr> pLogMgr;
pLog = pLogMgr->getLog();
}
XmlReader xml(pLog);
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* pDoc = xml.parse(filename, "metadata");
DOMElement* pRootElement = NULL;
if (pDoc != NULL)
{
pRootElement = pDoc->getDocumentElement();
}
if (pRootElement != NULL)
{
for (DOMNode* pChild = pRootElement->getFirstChild();
pChild != NULL;
pChild = pChild->getNextSibling())
{
if (pChild->getNodeType() == DOMNode::ELEMENT_NODE)
{
DOMElement* pChildElement = static_cast<DOMElement*>(pChild);
string cNodeName = A(pChildElement->getNodeName());
ImportDescriptor* pImportDescriptor = ModelImporter::populateImportDescriptor(pChildElement, filename);
if (pImportDescriptor != NULL)
{
DataDescriptor* pDataDescriptor = pImportDescriptor->getDataDescriptor();
if (NULL != pDataDescriptor)
{
DynamicObject* pMetadataZ = pDataDescriptor->getMetadata();
VERIFYRV(pMetadataZ, descriptors);
if (!pMetadataZ->getAttributeByPath("Layer/Import Options/Use Pixel Coordinates").isValid())
{
pMetadataZ->setAttributeByPath("Layer/Import Options/Use Pixel Coordinates", false);
}
}
descriptors.push_back(pImportDescriptor);
}
}
}
}
}
return descriptors;
}
示例6: sigNodeName
static DOMElement *
SAMLFindChildByName(const DOMElement *elem,
const char *name)
{
XMLT sigNodeName(name);
DOMElement *childElem;
for (childElem = elem->getFirstElementChild();
childElem != NULL; childElem = childElem->getNextElementSibling()) {
if (XMLString::equals(childElem->getNodeName(),
sigNodeName.getUnicodeStr())) {
break;
}
}
return childElem;
}
示例7: xml
vector<ImportDescriptor*> LayerImporter::getImportDescriptors(const string& filename, bool reportErrors)
{
vector<ImportDescriptor*> descriptors;
if (!filename.empty())
{
MessageLog* pLog = NULL;
if (reportErrors == true)
{
Service<MessageLogMgr> pLogMgr;
pLog = pLogMgr->getLog();
}
XmlReader xml(pLog);
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* pDoc = xml.parse(filename, "metadata");
DOMElement* pRootElement = NULL;
if (pDoc != NULL)
{
pRootElement = pDoc->getDocumentElement();
}
if (pRootElement != NULL)
{
for (DOMNode* pChild = pRootElement->getFirstChild();
pChild != NULL;
pChild = pChild->getNextSibling())
{
if (pChild->getNodeType() == DOMNode::ELEMENT_NODE)
{
DOMElement* pChildElement = static_cast<DOMElement*>(pChild);
string cNodeName = A(pChildElement->getNodeName());
ImportDescriptor* pImportDescriptor = ModelImporter::populateImportDescriptor(pChildElement, filename);
if (pImportDescriptor != NULL)
{
descriptors.push_back(pImportDescriptor);
}
}
}
}
}
return descriptors;
}
示例8: deserialize
bool SpectralLibraryManager::deserialize(SessionItemDeserializer& deserializer)
{
if (isBatch() == true)
{
setInteractive();
}
bool success = execute(NULL, NULL);
if (success)
{
std::vector<Signature*> signatures;
Service<SessionManager> pSessionManager;
XmlReader reader(NULL, false);
DOMElement* pRootElement = deserializer.deserialize(reader, "SpectralLibraryManager");
for (DOMNode* pChild = pRootElement->getFirstChild(); pChild != NULL; pChild = pChild->getNextSibling())
{
DOMElement* pElement = static_cast<DOMElement*>(pChild);
if (XMLString::equals(pElement->getNodeName(), X("Signature")))
{
std::string signatureId = A(pElement->getAttribute(X("signatureId")));
Signature* pSignature = dynamic_cast<Signature*>(pSessionManager->getSessionItem(signatureId));
if (pSignature != NULL)
{
signatures.push_back(pSignature);
}
}
}
clearLibrary();
addSignatures(signatures);
}
return success;
}
示例9: LoadDataBlock
ret_ CXMLLoaderActions::LoadDataBlock(CData &Data,
const DOMElement *pElement)
{
#ifdef _DEBUG_
if (!pElement)
return PARAMETER_NULL | PARAMETER_2;
#endif
DOMElement *pChild = (DOMElement *)pElement->getFirstChild();
if (!pChild)
return XML_LOADER_ERROR;
auto_xerces_str wsObject ("v_object");
auto_xerces_str wsB1 ("v_b_1");
auto_xerces_str wsUB1 ("v_ub_1");
auto_xerces_str wsB2 ("v_b_2");
auto_xerces_str wsUB2 ("v_ub_2");
auto_xerces_str wsB4 ("v_b_4");
auto_xerces_str wsUB4 ("v_ub_4");
auto_xerces_str wsB8 ("v_b_8");
auto_xerces_str wsUB8 ("v_ub_8");
auto_xerces_str wsFB4 ("v_fb_4");
auto_xerces_str wsFB8 ("v_fb_8");
auto_xerces_str wsString ("v_string");
auto_xerces_str wsGroup ("v_group");
auto_xerces_str wsName ("name");
auto_xerces_str wsValue ("value");
while (pChild)
{
if (0 == XMLString::compareString(pChild->getNodeName(), wsObject))
{
auto_xerces_str sName (pChild->getAttribute(wsName));
auto_xerces_str sValue (pChild->getAttribute(wsValue));
if (false_v == Data.Define(sName, (obj_)null_v))
return XML_LOADER_ERROR;
}
else if (0 == XMLString::compareString(pChild->getNodeName(), wsB1))
{
auto_xerces_str sName (pChild->getAttribute(wsName));
auto_xerces_str sValue (pChild->getAttribute(wsValue));
if (0 == strcmp(sValue, SIGN_UNBOUNDED))
{
if (false_v == Data.Define(sName, B_1))
return XML_LOADER_ERROR;
}
else
{
if (false_v == Data.Define(sName, B_1, (b_4)atoi(sValue)))
return XML_LOADER_ERROR;
}
}
else if (0 == XMLString::compareString(pChild->getNodeName(), wsUB1))
{
auto_xerces_str sName (pChild->getAttribute(wsName));
auto_xerces_str sValue (pChild->getAttribute(wsValue));
if (0 == strcmp(sValue, SIGN_UNBOUNDED))
{
if (false_v == Data.Define(sName, UB_1))
return XML_LOADER_ERROR;
}
else
{
if (false_v == Data.Define(sName, UB_1, (b_4)atoi(sValue)))
return XML_LOADER_ERROR;
}
}
else if (0 == XMLString::compareString(pChild->getNodeName(), wsB2))
{
auto_xerces_str sName (pChild->getAttribute(wsName));
auto_xerces_str sValue (pChild->getAttribute(wsValue));
if (0 == strcmp(sValue, SIGN_UNBOUNDED))
{
if (false_v == Data.Define(sName, B_2))
return XML_LOADER_ERROR;
}
else
{
if (false_v == Data.Define(sName, B_2, (b_4)atoi(sValue)))
return XML_LOADER_ERROR;
}
}
else if (0 == XMLString::compareString(pChild->getNodeName(), wsUB2))
{
auto_xerces_str sName (pChild->getAttribute(wsName));
auto_xerces_str sValue (pChild->getAttribute(wsValue));
if (0 == strcmp(sValue, SIGN_UNBOUNDED))
{
if (false_v == Data.Define(sName, UB_2))
return XML_LOADER_ERROR;
}
else
//.........这里部分代码省略.........
示例10: LoadIf
ret_ CXMLLoaderActions::LoadIf(CProgram &Program,
const DOMElement *pElement,
const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
if (!pElement)
return (PARAMETER_NULL | PARAMETER_3);
#endif
DOMElement *pSub = (DOMElement *)pElement->getFirstChild();
if (!pSub)
return XML_LOADER_ERROR;
auto_xerces_str wsDataBlock ("data_block");
auto_xerces_str wsExpressionUnitary ("expression_unitary");
auto_xerces_str wsExpressionDuality ("expression_duality");
auto_xerces_str wsConditionUnitary ("condition_unitary");
auto_xerces_str wsConditionDuality ("condition_duality");
auto_xerces_str wsProgram ("program");
CProgramIf *pPI = new CProgramIf();
pPI->Data().SetParent(&Program.Data());
while (pSub)
{
if (0 == XMLString::compareString(pSub->getNodeName(),
wsDataBlock))
{
CData Data;
if (SUCCESS != (LoadDataBlock(Data, pSub)))
return XML_LOADER_ERROR;
pPI->SetData(Data);
}
else if (0 == XMLString::compareString(pSub->getNodeName(),
wsExpressionUnitary)
|| 0 == XMLString::compareString(pSub->getNodeName(),
wsExpressionDuality)
|| 0 == XMLString::compareString(pSub->getNodeName(),
wsConditionUnitary)
|| 0 == XMLString::compareString(pSub->getNodeName(),
wsConditionDuality))
{
CExpression *pExpression = null_v;
if (SUCCESS != LoadExpression(pPI->Data(),
pSub,
pExpression,
pPDU))
{
return XML_LOADER_ERROR;
}
if (false_v == pPI->AddExpression(pExpression))
return XML_LOADER_ERROR;
}
else if (0 == XMLString::compareString(pSub->getNodeName(),
wsProgram))
{
CProgram *pProgram = new CProgram();
if (SUCCESS != LoadProgram(&pPI->Data(),
*pProgram,
pSub,
pPDU))
{
return XML_LOADER_ERROR;
}
if (false_v == pPI->AddOperator(pProgram))
return XML_LOADER_ERROR;
}
pSub = (DOMElement *)pSub->getNextSibling();
}
if (false_v == Program.AddOperator(pPI))
return XML_LOADER_ERROR;
return SUCCESS;
}
示例11: LoadConfigGroup
ret_ CXMLLoaderActions::LoadConfigGroup(CProgram &Program,
const DOMElement *pElement,
const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
if (!pElement)
return (PARAMETER_NULL | PARAMETER_2);
#endif
//
DOMElement *pSub = (DOMElement *)pElement->getFirstChild();
if (!pSub)
return XML_LOADER_ERROR;
CAutoPtr<CVariable> OV[2];
size_ n = 0;
while (pSub)
{
if (0 == XMLString::compareString(pSub->getNodeName(),
m_wsGroupVariable))
{
if (SUCCESS != LoadGroupVariable(Program.Data(),
pElement,
OV[0].Ptr()))
{
return XML_LOADER_ERROR;
}
n++;
break;
}
pSub = (DOMElement *)pSub->getNextSibling();
}
pSub = (DOMElement *)pSub->getNextSibling();
while (pSub)
{
if (0 == XMLString::compareString(pSub->getNodeName(),
m_wsSolidVariable))
{
if (SUCCESS != LoadSolidVariable(Program.Data(),
pElement,
OV[1].Ptr()))
{
return XML_LOADER_ERROR;
}
n++;
break;
}
pSub = (DOMElement *)pSub->getNextSibling();
}
if (2 != n)
return XML_LOADER_ERROR;
COptConfigGroup *pOperator = new COptConfigGroup(OV[0].Ptr(), OV[1].Ptr());
if (false_v == Program.AddOperator(pOperator))
return XML_LOADER_ERROR;
return SUCCESS;
}
示例12: Load
ret_ CXMLLoaderActions::Load(XercesDOMParser *pParser,
const ch_1 *pszEnvironmentPath)
{
#ifdef _DEBUG_
if (!pParser)
return PARAMETER_NULL | PARAMETER_1;
if (!pszEnvironmentPath)
return PARAMETER_NULL | PARAMETER_2;
if (null_v == pszEnvironmentPath[0])
return PARAMETER_EMPTY | PARAMETER_2;
#endif
SetParser(pParser);
ch_1 sActions[ENVIRONMENT_PATH_LENGTH];
memset(sActions, 0, ENVIRONMENT_PATH_LENGTH);
sprintf(sActions, "%s%s", pszEnvironmentPath, ACTIONS_XML_FILE);
DOMDocument *pActionsDoc = null_v;
try
{
GetParser()->parse(sActions);
pActionsDoc = GetParser()->getDocument();
}
catch (const OutOfMemoryException &err)
{
auto_xerces_str sErr(err.getMessage());
printf("%s\n", (const ch_1 *)sErr);
return XML_LOADER_ERROR;
}
catch (const XMLException &err)
{
auto_xerces_str sErr(err.getMessage());
printf("%s\n", (const ch_1 *)sErr);
return XML_LOADER_ERROR;
}
catch (const DOMException &err)
{
auto_xerces_str sErr(err.msg);
printf("%s\n", (const ch_1 *)sErr);
return XML_LOADER_ERROR;
}
catch (...)
{
printf("Unexpected error during parsing.\n");
return XML_LOADER_ERROR;
}
if (!pActionsDoc)
return XML_LOADER_ERROR;
DOMElement *pRoot = pActionsDoc->getDocumentElement();
if (!pRoot)
return XML_LOADER_ERROR;
DOMElement *pChild = (DOMElement *)pRoot->getFirstChild();
if (!pChild)
return XML_LOADER_ERROR;
auto_xerces_str wsDataBlock("data_block");
auto_xerces_str wsStart("start");
auto_xerces_str wsProcessor("processor");
auto_xerces_str wsEnd("end");
while (pChild)
{
if (0 == XMLString::compareString(pChild->getNodeName(),
wsDataBlock))
{
if (SUCCESS != LoadDataBlock(CUIManager::Instance()->Data(),
pChild))
{
return XML_LOADER_ERROR;
}
}
else if (0 == XMLString::compareString(pChild->getNodeName(),
wsStart))
{
if (SUCCESS != LoadProgram(&CUIManager::Instance()->Data(),
CUIManager::Instance()->StartProgram(),
pChild))
{
return XML_LOADER_ERROR;
}
}
else if (0 == XMLString::compareString(pChild->getNodeName(),
wsProcessor))
//.........这里部分代码省略.........
示例13: LoadProcessBlock
ret_ CXMLLoaderActions::LoadProcessBlock(CProgram &Program,
const DOMElement *pElement,
const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
if (!pElement)
return (PARAMETER_NULL | PARAMETER_2);
#endif
DOMElement *pChild = (DOMElement *)pElement->getFirstChild();
if (!pChild)
return XML_LOADER_ERROR;
auto_xerces_str wsEmpty ("empty");
auto_xerces_str wsUnitaryCalculate ("unitary_calculate");
auto_xerces_str wsDualityCalculate ("duality_calculate");
auto_xerces_str wsConfigGroup ("config_group");
auto_xerces_str wsIf ("if");
auto_xerces_str wsWhile ("while");
auto_xerces_str wsContinue ("continue");
auto_xerces_str wsBlock ("block");
auto_xerces_str wsBreak ("break");
auto_xerces_str wsSend ("send");
auto_xerces_str wsReadFile ("read_file");
auto_xerces_str wsSaveFile ("save_file");
auto_xerces_str wsDeleteFile ("delete_file");
auto_xerces_str wsSplit ("split");
auto_xerces_str wsDie ("die");
auto_xerces_str wsShowWindow ("show_window");
auto_xerces_str wsWaitMessage ("wait_message");
auto_xerces_str wsAlert ("alert");
auto_xerces_str wsEnable ("enable");
auto_xerces_str wsAddItem ("add_item");
auto_xerces_str wsProgram ("program");
while (pChild)
{
if (0 == XMLString::compareString(pChild->getNodeName(),
wsEmpty))
{
if (SUCCESS != LoadEmpty(Program, pChild, pPDU))
return XML_LOADER_ERROR;
}
else if (0 == XMLString::compareString(pChild->getNodeName(),
wsUnitaryCalculate))
{
if (SUCCESS != LoadUnitaryCalculate(Program, pChild, pPDU))
return XML_LOADER_ERROR;
}
else if (0 == XMLString::compareString(pChild->getNodeName(),
wsDualityCalculate))
{
if (SUCCESS != LoadDualityCalculate(Program, pChild, pPDU))
return XML_LOADER_ERROR;
}
else if (0 == XMLString::compareString(pChild->getNodeName(),
wsConfigGroup))
{
if (SUCCESS != LoadConfigGroup(Program, pChild, pPDU))
return XML_LOADER_ERROR;
}
else if (0 == XMLString::compareString(pChild->getNodeName(),
wsIf))
{
if (SUCCESS != LoadIf(Program, pChild, pPDU))
return XML_LOADER_ERROR;
}
else if (0 == XMLString::compareString(pChild->getNodeName(),
wsWhile))
{
if (SUCCESS != LoadWhile(Program, pChild, pPDU))
return XML_LOADER_ERROR;
}
else if (0 == XMLString::compareString(pChild->getNodeName(),
wsContinue))
{
if (SUCCESS != LoadContinue(Program))
return XML_LOADER_ERROR;
}
else if (0 == XMLString::compareString(pChild->getNodeName(),
wsBlock))
{
if (SUCCESS != LoadBlock(Program))
return XML_LOADER_ERROR;
}
else if (0 == XMLString::compareString(pChild->getNodeName(),
wsBreak))
{
if (SUCCESS != LoadBreak(Program))
return XML_LOADER_ERROR;
}
else if (0 == XMLString::compareString(pChild->getNodeName(),
wsSend))
{
if (SUCCESS != LoadSend(Program, pChild, pPDU))
return XML_LOADER_ERROR;
}
else if (0 == XMLString::compareString(pChild->getNodeName(),
wsReadFile))
//.........这里部分代码省略.........
示例14: Load
//.........这里部分代码省略.........
auto_xerces_str wsIdentity ("identity");
auto_xerces_str wsPDU ("pdu");
auto_xerces_str wsDirection ("direction");
auto_xerces_str wsName ("name");
auto_xerces_str wsProtocolName ("protocol");
auto_xerces_str wsCommandID ("command_id");
auto_xerces_str wsSizeID ("size_id");
auto_xerces_str wsLocalPort ("local_port");
auto_xerces_str wsAuto ("auto");
auto_xerces_str wsFilter ("filter");
auto_xerces_str wsMaxConnections("max_connections");
auto_xerces_str wsRemoteIP ("remote_ip");
auto_xerces_str wsRemotePort ("remote_port");
auto_xerces_str wsReconnect ("reconnect");
auto_xerces_str wsAcceptorName ("acceptor");
auto_xerces_str wsConnectorName ("connector");
auto_xerces_str wsReceiverName ("receiver");
auto_xerces_str wsSenderName ("sender");
auto_xerces_str wsType ("type");
while (pChild)
{
ENetworkType NetworkType = NETWORK_NONE;
CProtocolInfo *pProtocol = null_v;
CField *pCommandIDField = null_v;
CField *pSizeIDField = null_v;
bool_ bIsAutoStart = true_v;
if (0 == XMLString::compareString(pChild->getNodeName(),
wsAcceptorName))
{
NetworkType = NETWORK_ACCEPTOR;
}
else if (0 == XMLString::compareString(pChild->getNodeName(),
wsConnectorName))
{
NetworkType = NETWORK_CONNECTOR;
}
else if (0 == XMLString::compareString(pChild->getNodeName(),
wsReceiverName))
{
NetworkType = NETWORK_RECEIVER;
}
else if (0 == XMLString::compareString(pChild->getNodeName(),
wsSenderName))
{
NetworkType = NETWORK_SENDER;
}
else
{
pChild = (DOMElement *)pChild->getNextSibling();
continue;
}
auto_xerces_str sProtocolName(pChild->getAttribute(wsProtocolName));
if (SUCCESS != _ERR(
CXMLLoaderProtocol::Instance()->Load(pParser,
pszEnvironmentPath,
sProtocolName)))
示例15: Read
bool XmlWorldReader::Read(const std::string &file) {
// ワールドを初期化
try {
initialize();
if (initFlag) {
initializeWorld();
}
} catch (...) {
return false;
}
// TODO: ファイルの有無を確認
// XMLファイルをパース
const XMLCh gLS[] = {chLatin_L, chLatin_S, chNull};
DOMImplementationLS *impl = DOMImplementationRegistry::getDOMImplementation(gLS);
DOMLSParser *parser = impl->createLSParser(
DOMImplementationLS::MODE_SYNCHRONOUS, NULL
);
DOMDocument *doc = parser->parseURI(file.c_str());
if (doc == nullptr) {
return false;
}
// rootノードを取得
DOMElement *worldElement = doc->getDocumentElement();
if (worldElement == nullptr) {
parser->release();
return false;
}
{
YPT::XmlString temp("world");
bool res = XMLString::equals(worldElement->getNodeName(), temp);
if (!res) {
parser->release();
return false;
}
}
// ロード用クラス作成
YPT::XmlWorldPartReader partReader(doc);
// XPathコンテキスト作成
DOMXPathNSResolver *resolver = doc->createNSResolver(worldElement);
if (resolver == nullptr) {
parser->release();
return false;
}
YPT::XmlString str, str2;
DOMXPathResult *result;
// --------------------------------------------------
// ワールド全体の設定
// --------------------------------------------------
// ワールド名
str = worldElement->getAttribute(YPT::XmlString("name"));
if (str != "") {
name = str;
}
// 重力ベクトル
result = doc->evaluate(
YPT::XmlString("./gravity"), worldElement, resolver,
DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
NULL
);
if (result != nullptr) {
if (result->getSnapshotLength() >= 1) {
str = result->getNodeValue()->getTextContent();
b2Vec2 temp;
if (!YPT::ConvertStrToVec2(str.ToChar(), &temp)) {
world.SetGravity(temp);
}
}
result->release();
}
// --------------------------------------------------
// shapes
// --------------------------------------------------
result = doc->evaluate(
YPT::XmlString("./shape"), worldElement, resolver,
DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
NULL
);
if (result != nullptr) {
const XMLSize_t len = result->getSnapshotLength();
for (XMLSize_t i = 0; i < len; ++i) {
result->snapshotItem(i);
DOMNode *node = result->getNodeValue();
if (node == nullptr) {
continue;
}
DOMNamedNodeMap *nodeMap = node->getAttributes();
if (nodeMap == nullptr) {
continue;
}
//.........这里部分代码省略.........