void processOptions(store::Item_t item, store::LoadProperties& props, static_context* theSctx, const QueryLoc& loc) { URI lValidatedBaseUri; store::Item_t child, tempItem; if (item.getp() == NULL) return; #ifndef ZORBA_NO_XMLSCHEMA if (item->isValidated()) { if (item->getNodeName() == NULL || item->getNodeName()->getNamespace() != static_context::ZORBA_XML_FN_OPTIONS_NS) { throw XQUERY_EXCEPTION(zerr::ZXQD0003_INCONSISTENT_PARSE_FRAGMENT_OPTIONS, ERROR_PARAMS(ZED(ParseFragmentInvalidOptions)), ERROR_LOC( loc )); } } else { tempItem = NULL; // used as the effectiveValidationValue()'s typeName Validator::effectiveValidationValue( item, item, tempItem, theSctx->get_typemanager(), ParseConstants::val_strict, theSctx, loc); } #endif store::Iterator_t children = item->getChildren(); children->open(); while (children->next(child)) { if (child->getNodeKind() != store::StoreConsts::elementNode) continue; if (child->getNodeName()->getLocalName() == "base-uri") { store::Item_t attr = getFirstAttribute(child); try { lValidatedBaseUri = URI(attr->getStringValue()); } catch (ZorbaException const& /* e */) { throw XQUERY_EXCEPTION( err::FODC0007, ERROR_PARAMS( attr->getStringValue() ), ERROR_LOC( loc ) ); } if (!lValidatedBaseUri.is_absolute()) { throw XQUERY_EXCEPTION( err::FODC0007, ERROR_PARAMS( lValidatedBaseUri.toString() ), ERROR_LOC( loc ) ); } props.setBaseUri(attr->getStringValue()); } else if (child->getNodeName()->getLocalName() == "no-error") props.setNoError(true); else if (child->getNodeName()->getLocalName() == "strip-boundary-space") props.setStripWhitespace(true); else if (child->getNodeName()->getLocalName() == "schema-validate") { store::Item_t attr = getFirstAttribute(child); if (attr->getStringValue() == "strict") props.setSchemaStrictValidate(true); else props.setSchemaLaxValidate(true); } else if (child->getNodeName()->getLocalName() == "DTD-validate") props.setDTDValidate(true); else if (child->getNodeName()->getLocalName() == "DTD-load") props.setDTDLoad(true); else if (child->getNodeName()->getLocalName() == "default-DTD-attributes") props.setDefaultDTDAttributes(true); else if (child->getNodeName()->getLocalName() == "parse-external-parsed-entity") { props.setParseExternalParsedEntity(true); store::Item_t attr; store::Iterator_t attribs = child->getAttributes(); attribs->open(); while (attribs->next(attr)) { if (attr->getNodeName()->getLocalName() == "skip-root-nodes") props.setSkipRootNodes(ztd::aton<xs_int>(attr->getStringValue().c_str())); else if (attr->getNodeName()->getLocalName() == "skip-top-level-text-nodes") props.setSkipTopLevelTextNodes(true); else if (attr->getNodeName()->getLocalName() == "error-on-doctype") props.setErrorOnDoctype(true); } attribs->close(); } else if (child->getNodeName()->getLocalName() == "substitute-entities") props.setSubstituteEntities(true); else if (child->getNodeName()->getLocalName() == "xinclude-substitutions") props.setXincludeSubstitutions(true); else if (child->getNodeName()->getLocalName() == "remove-redundant-ns") props.setRemoveRedundantNS(true); else if (child->getNodeName()->getLocalName() == "no-CDATA") props.setNoCDATA(true); else if (child->getNodeName()->getLocalName() == "no-xinclude-nodes") props.setNoXIncludeNodes(true); else if (child->getNodeName()->getLocalName() == "no-network-access") props.setNoNetworkAccess(true); } children->close(); if (props.getSchemaLaxValidate() + props.getSchemaStrictValidate() + props.getDTDValidate() + props.getParseExternalParsedEntity() > 1) { throw XQUERY_EXCEPTION(zerr::ZXQD0003_INCONSISTENT_PARSE_FRAGMENT_OPTIONS, ERROR_PARAMS(ZED(ParseFragmentOptionCombinationNotAllowed)), ERROR_LOC( loc )); } }
// -------------------------------------------------------------- void CollectionParserSLC::_parse( std::ifstream& file, Collection& collection ) { rapidxml::xml_document<> doc; // Read file into vector<char> std::vector<char> buffer( ( std::istreambuf_iterator<char>( file ) ), std::istreambuf_iterator<char>( ) ); buffer.push_back( '\0' ); try { // parse the darn thing with rapidxml doc.parse<0>( &buffer[0] ); } catch( rapidxml::parse_error& e ) { throw Exception( std::string("Error during xml parsing: ") + e.what() ); } rapidxml::xml_node<>* rootNode = getFirstNode( &doc, "SokobanLevels" ); // read all the meta tags into the metaTagValues array std::string metaTagValues [NUM_META_TAG_NAMES]; for( int i = 0; i < NUM_META_TAG_NAMES; ++i ) { rapidxml::xml_node<>* metaTag = getFirstNode( rootNode, META_TAG_NAMES[i] ); if (metaTag != 0) // if there actually is such a meta tag { metaTagValues[i] = metaTag->value(); } } rapidxml::xml_node<>* levelCollectionNode = getFirstNode(rootNode, "LevelCollection"); std::string levelCollectionCopyright = getFirstAttribute(levelCollectionNode, "Copyright"); for( rapidxml::xml_node<>* levelNode = levelCollectionNode->first_node("Level"); levelNode; levelNode = levelNode->next_sibling() ) { std::string levelName = getFirstAttribute(levelNode, "Id"); Level* lvl; // = listener->_constructNewLevel(); lvl->addMetaData("Author", levelCollectionCopyright); // set the meta tags from the collection tag for the level for( int i = 0; i < NUM_META_TAG_NAMES; ++i ) { lvl->addMetaData(META_TAG_NAMES[i], metaTagValues[i]); } //listener->_generateLevelName( levelName ); lvl->setLevelName( levelName ); int y = 0; for( rapidxml::xml_node<>* levelLineNode = levelNode->first_node("L"); levelLineNode; levelLineNode = levelLineNode->next_sibling() ) { lvl->insertTileLine(y++, levelLineNode->value()); } } //TODO return metaTagValues[0]; }