• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ XQuery_t类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中XQuery_t的典型用法代码示例。如果您正苦于以下问题:C++ XQuery_t类的具体用法?C++ XQuery_t怎么用?C++ XQuery_t使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了XQuery_t类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: test_serialization_error

// test for bug #3085093 "ZorbaError not caught in SerializerImpl::serialize"
bool
test_serialization_error(Zorba* aZorba)
{
  XQuery_t lQuery = aZorba->compileQuery("<a a='1'/>/@a"); 

  Zorba_SerializerOptions_t lOptions;
  Serializer_t lSerializer = Serializer::createSerializer(lOptions);

  Iterator_t lIterator = lQuery->iterator();

  try {
    lIterator->open();

    Item lItem;
    while ( lIterator->next(lItem) ) {
      // we have to wrap the item in a Serializable object
      SingletonItemSequence lSequence(lItem);
      lSerializer->serialize(&lSequence, std::cout);
    }

    lIterator->close();

  } catch (ZorbaException& e) {
    std::cerr << e << std::endl;
    lIterator->close();
    return true;
  }
	return false;
}
开发者ID:alyst,项目名称:zorba,代码行数:30,代码来源:serializer.cpp


示例2: sax2

int sax2( int argc, char * argv[] )
{
  // create a SAX content handler that prints all events to standard out
  XMLSerializer lContentHandler( std::cout );

  void* lStore = zorba::StoreManager::getStore();

  // initialize the Zorba engine and get a pointer to it
  Zorba* lZorba = Zorba::getInstance(lStore);

  try 
  {
    // compile a query
    XQuery_t lQuery = lZorba->compileQuery("<a xmlns:f=\"foo\" xmlns=\"http://zorba.io/defaultns\"> text a text a <b xmlns:ns1=\"http://zorba.io/usecase1\" attr1=\"value1\" attr2=\"value2\"> text b </b><f:bar>foo</f:bar><foo /><bar /><b><![CDATA[ foo ]]></b></a>");

    // register the content handler created above
    lQuery->registerSAXHandler( &lContentHandler );

    // execute the query and call according SAX callbacks 
    // i.e. equivalent to serializing to xml and parsing using SAX).
    lQuery->executeSAX();
  }
  catch ( ZorbaException &e ) 
  {
    std::cerr << e << std::endl;
  }

  lZorba->shutdown();
  zorba::StoreManager::shutdownStore(lStore);
  return 0;
}
开发者ID:zorba-processor,项目名称:zorba,代码行数:31,代码来源:sax2.cpp


示例3: cxx_api_changes_test2

bool 
cxx_api_changes_test2 (Zorba* aZorba)
{
  try
  {
    //test the use of the isSequential function in the c++ API
    std::ifstream lIn("cxx_api_ch2.xq");
    assert(lIn.good());
    
    XQuery_t lQuery = aZorba->compileQuery(lIn);

    if(lQuery->isSequential())
      return false;
  }
  catch (XQueryException& qe)
  {
    std::cerr << qe << std::endl;
    return false;
  }
  catch (ZorbaException& e)
  {
    std::cerr << e << std::endl;
    return false;
  }

  return true;
}
开发者ID:alyst,项目名称:zorba,代码行数:27,代码来源:cxx_api_changes.cpp


示例4: example_1

/**
 * Test accessing a JSONArray's members
 */
bool
example_1(Zorba* aZorba)
{
  Iterator_t lIterator;
  XQuery_t lQuery = aZorba->compileQuery("[ 1, 2, 3 ]");
  lIterator = lQuery->iterator();
  lIterator->open();
  Item lItem;
  lIterator->next(lItem);

  // Ensure we got a JSON array
  if (!lItem.isJSONItem() ||
      lItem.getJSONItemKind() != store::StoreConsts::jsonArray) {
    std::cerr << "Item is not JSON Array!" << std::endl;
    return false;
  }

  // Ensure array has 3 integer members
  uint64_t lSize = lItem.getArraySize();
  if (lSize != 3) {
    std::cerr << lSize << " array members returned, expecting 3" << std::endl;
    return false;
  }
  for(uint64_t i = 1; i <= lSize; ++i)
  {
    Item lMember = lItem.getArrayValue(i);
    // This will throw an exception if the item isn't an integer
    std::cout << lMember.getLongValue() << std::endl;
  }
  lIterator->close();

  return true;
}
开发者ID:zorba-processor,项目名称:zorba,代码行数:36,代码来源:jsoniq.cpp


示例5: cxx_api_changes_test4

bool 
cxx_api_changes_test4(Zorba* aZorba)
{
  try
  {
    std::ifstream lIn("cxx_api_ch4.xq");
    assert(lIn.good());

    StaticContext_t lStaticContext = aZorba->createStaticContext();
    std::vector<String> lModulePaths;
    lModulePaths.push_back(zorba::CMAKE_BINARY_DIR+"/TEST_URI_PATH/");
    lStaticContext->setModulePaths(lModulePaths);
    
    XQuery_t lQuery = aZorba->compileQuery(lIn, lStaticContext);
    std::vector<Item> lVars;
    Iterator_t varsIte;
    lQuery->getExternalVariables(varsIte);

    varsIte->open();
    Item temp;
    while(varsIte->next(temp))
      lVars.push_back(temp);
    varsIte->close();

    if (lVars.size() != 3)
      return false;

    std::ostringstream lOut;
    std::vector<Item>::const_iterator lIte = lVars.begin();
    std::vector<Item>::const_iterator lEnd = lVars.end();
    
    for (; lIte != lEnd; ++lIte)
    {
      lOut << lIte->getStringValue() << " ";
    }

    std::string out = lOut.str();

    if (out != "testGetExtVarA:ext a testGetExtVarB:ext " &&
        out != "testGetExtVarB:ext a testGetExtVarA:ext " &&
        out != "a testGetExtVarA:ext testGetExtVarB:ext " &&
        out != "a testGetExtVarB:ext testGetExtVarA:ext " &&
        out != "testGetExtVarA:ext testGetExtVarB:ext a " &&
        out != "testGetExtVarB:ext testGetExtVarA:ext a ")
      return false;
  }
  catch (XQueryException& qe)
  {
    std::cerr << qe << std::endl;
    return false;
  }
  catch (ZorbaException& e)
  {
    std::cerr << e << std::endl;
    return false;
  }

  return true;
}
开发者ID:alyst,项目名称:zorba,代码行数:59,代码来源:cxx_api_changes.cpp


示例6: external_function_test_2

bool
external_function_test_2(Zorba* aZorba)
{
  try 
  {
    std::ifstream lIn("ext_main.xq");
    assert(lIn.good());
    std::ostringstream lOut;
    MyExternalModule lMod;

    StaticContext_t lSctx = aZorba->createStaticContext();
    lSctx->registerModule(&lMod);
    {
      XQuery_t lQuery = aZorba->compileQuery(lIn, lSctx);

      zorba::DynamicContext* lDynContext = lQuery->getDynamicContext();

      // must be released in MyExternalFunctionParameter::destroy
      MyExternalFunctionParameter* lParam1 = new MyExternalFunctionParameter();
      MyExternalFunctionParameter* lParam2 = new MyExternalFunctionParameter();

      lDynContext->addExternalFunctionParameter("myparam", lParam1);
      lDynContext->addExternalFunctionParameter("myparam", lParam2);

      // make sure that destroy is invoked if the first parameter is overwritten
      if (!lDestroyedParam)
      {
        return false;
      }
      else
      {
        lDestroyedParam = false;
      }

      lDynContext->setVariable("local:foo",
                               aZorba->getItemFactory()->createString("foo")); 

      std::cout << lQuery << std::endl;
    }

    // destroy is called if the XQuery object is destroyed
    return lGotParam && lDestroyedParam;

  } 
  catch (XQueryException& qe) 
  {
    std::cerr << qe << std::endl;
    return false;
  }
  catch (ZorbaException& e)
  {
    std::cerr << e << std::endl;
    return false;
  }
  return true;
}
开发者ID:alyst,项目名称:zorba,代码行数:56,代码来源:external_function.cpp


示例7: cxx_api_changes_test5

bool
cxx_api_changes_test5(Zorba* aZorba)
{
  try
  {
    
    std::string lIn = "declare variable $a external; 1+1";
    
    XQuery_t lQuery = aZorba->compileQuery(lIn);

    std::vector<Item> lVars;
    Iterator_t varsIte;
    lQuery->getExternalVariables(varsIte);

    varsIte->open();
    Item temp;
    while(varsIte->next(temp))
      lVars.push_back(temp);
    varsIte->close();

    std::vector<Item>::const_iterator lIte = lVars.begin();
    std::vector<Item>::const_iterator lEnd = lVars.end();

    Item item = aZorba->getItemFactory()->createInt(4);
    

    bool isBound1;
    bool isBound2;

    for(; lIte != lEnd; ++lIte)
    {
      Item qname = *lIte;
      isBound1 = lQuery->getDynamicContext()->isBoundExternalVariable(qname.getNamespace(), qname.getLocalName());
      Item value = aZorba->getItemFactory()->createString("foo");
      lQuery->getDynamicContext()->setVariable(qname.getStringValue(), value);
      isBound2 = lQuery->getDynamicContext()->isBoundExternalVariable(qname.getNamespace(), qname.getLocalName());
    }

    if (!isBound1 && isBound2)
      return true;
     
  }
  catch (XQueryException& qe)
  {
    std::cerr << qe << std::endl;
    return false;
  }
  catch (ZorbaException& e)
  {
    std::cerr << e << std::endl;
    return false;
  }

  return true;
}
开发者ID:alyst,项目名称:zorba,代码行数:55,代码来源:cxx_api_changes.cpp


示例8: cxx_api_changes_test3

bool
cxx_api_changes_test3(Zorba* aZorba)
{
  try
  {
    //tests the use of getExternalVariables
    std::ifstream lIn("cxx_api_ch3.xq");
    assert(lIn.good());

    XQuery_t lQuery = aZorba->compileQuery(lIn);

    std::vector<Item> lVars;
    Iterator_t varsIte;
    lQuery->getExternalVariables(varsIte);

    varsIte->open();
    Item temp;
    while(varsIte->next(temp))
      lVars.push_back(temp);
    varsIte->close();

    if (lVars.size() != 2)
    {
      std::cout << "Expected 2 variables but got " << lVars.size() << std::endl;
      return false;
    }

    std::vector<Item>::iterator lIte = lVars.begin();
    std::vector<Item>::iterator lEnd = lVars.end();
    
    for (; lIte != lEnd; ++lIte) 
    {
      String name = lIte->getStringValue();

      if (name != "a" && name != "b")
        return false;
    }
  }
  catch (XQueryException& qe)
  {
    std::cerr << qe << std::endl;
    return false;
  }
  catch (ZorbaException& e)
  {
    std::cerr << e << std::endl;

    return false;
  }

  return true;
}
开发者ID:alyst,项目名称:zorba,代码行数:52,代码来源:cxx_api_changes.cpp


示例9: serialization_example_2

/**
 * Example to invoke the serializer using the serialize() call on the query object.
 */
bool
serialization_example_2(Zorba* aZorba)
{
    try {
        XQuery_t lQuery = aZorba->compileQuery("for $i in (1 to 3) return <a> { $i } </a>");

        lQuery->execute(std::cout);
    } catch (ZorbaException& e) {
        std::cerr << e << std::endl;
        return false;
    }

    return true;
}
开发者ID:jensopetersen,项目名称:zorba,代码行数:17,代码来源:serialization.cpp


示例10: example1

 bool example1()
 {
   std::stringstream lStr;
   lStr << "(<anXMLExample/>, ";
   lStr << "<json type='object'><pair name='firstName' type='string'>";
   lStr << "John</pair></json>, ";
   lStr << "42)";
   XQuery_t lQuery = theZorba->compileQuery(lStr.str());
   try {
     lQuery->execute(std::cout, callback, this);
   } catch (ZorbaException& e) {
     std::cerr << e << std::endl;
     return false;
   }
   return true;
 }
开发者ID:zorba-processor,项目名称:zorba,代码行数:16,代码来源:callback.cpp


示例11: serialization_example_4

/**
 * Example to serialize the result of a query with indentation.
 */
bool
serialization_example_4(Zorba* aZorba)
{
    try {
        XQuery_t lQuery = aZorba->compileQuery("for $i in (1 to 3) return <a> { $i } </a>");

        Zorba_SerializerOptions lSerOptions;
        lSerOptions.indent = ZORBA_INDENT_YES;

        lQuery->execute(std::cout, &lSerOptions);
    } catch (ZorbaException& e) {
        std::cerr << e << std::endl;
        return false;
    }

    return true;
}
开发者ID:jensopetersen,项目名称:zorba,代码行数:20,代码来源:serialization.cpp


示例12: serialization_example_3

/**
 * Example that shows HTML serialization of the results.
 */
bool
serialization_example_3(Zorba* aZorba)
{
    try {
        XQuery_t lQuery = aZorba->compileQuery("for $i in (1 to 3) return <a> { $i } </a>");

        Zorba_SerializerOptions lSerOptions;
        lSerOptions.ser_method = ZORBA_SERIALIZATION_METHOD_HTML;

        lQuery->execute(std::cout, &lSerOptions);
    } catch (ZorbaException& e) {
        std::cerr << e << std::endl;
        return false;
    }

    return true;
}
开发者ID:jensopetersen,项目名称:zorba,代码行数:20,代码来源:serialization.cpp


示例13: serialization_example_6

bool
serialization_example_6(Zorba* aZorba)
{
    try {
        XQuery_t lQuery = aZorba->compileQuery("for $i in (1 to 3) return <a> { $i } </a>");

        Zorba_SerializerOptions lSerOptions;
        lSerOptions.byte_order_mark = ZORBA_BYTE_ORDER_MARK_YES;

        lQuery->execute(std::cout, &lSerOptions);
    } catch (ZorbaException& e) {
        std::cerr << e << std::endl;
        return false;
    }

    return true;
}
开发者ID:jensopetersen,项目名称:zorba,代码行数:17,代码来源:serialization.cpp


示例14: serialization_example_5

bool
serialization_example_5(Zorba* aZorba)
{
    try {
        XQuery_t lQuery = aZorba->compileQuery("for $i in (1 to 3) return <a> { $i } </a>");

        Zorba_SerializerOptions lSerOptions;
        lSerOptions.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;

        lQuery->execute(std::cout, &lSerOptions);
    } catch (ZorbaException& e) {
        std::cerr << e << std::endl;
        return false;
    }

    return true;
}
开发者ID:jensopetersen,项目名称:zorba,代码行数:17,代码来源:serialization.cpp


示例15: example_2

bool
example_2(Zorba* aZorba)
{
    XQuery_t lQuery = aZorba->createQuery();
    std::string path( "/home/adam/proj/marc2bibframe/xbin/zorba3-0.xqy");

    std::unique_ptr<std::istream> qfile;

    qfile.reset( new std::ifstream( path.c_str() ) );

    Zorba_CompilerHints lHints;

    // lQuery->setFileName("http://base/");
    lQuery->setFileName("/home/adam/proj/marc2bibframe/xbin/");

    lQuery->compile(*qfile, lHints);

    zorba::DynamicContext* lDynamicContext = lQuery->getDynamicContext();

    zorba::Item lItem = aZorba->getItemFactory()->createString("http://base/");
    lDynamicContext->setVariable("baseuri", lItem);

    lItem = aZorba->getItemFactory()->createString(
        "/home/adam/proj/yaz/test/marc6.xml");
    lDynamicContext->setVariable("marcxmluri", lItem);

    lItem = aZorba->getItemFactory()->createString("rdfxml");
    lDynamicContext->setVariable("serialization", lItem);

    std::cout << lQuery << std::endl;

    lItem = aZorba->getItemFactory()->createString(
        "/home/adam/proj/yaz/test/marc7.xml");
    lDynamicContext->setVariable("marcxmluri", lItem);

    std::stringstream ss;

    lQuery->execute(ss);

    std::string result = ss.str();

    std::cout << result << std::endl;

    return true;
}
开发者ID:dcrossleyau,项目名称:mp-xquery,代码行数:45,代码来源:tst.cpp


示例16: example_5

/**
 * Test accessing a non-existent JSONObject pair value
 */
bool
example_5(Zorba* aZorba)
{
  Iterator_t lIterator;
  XQuery_t lQuery = aZorba->compileQuery("{ \"one\" : 1, \"two\" : 2 }");
  lIterator = lQuery->iterator();
  lIterator->open();
  Item lItem;
  lIterator->next(lItem);

  Item lNonValue = lItem.getObjectValue("three");
  lIterator->close();

  if (!lNonValue.isNull()) {
    return false;
  }
  return true;
}
开发者ID:zorba-processor,项目名称:zorba,代码行数:21,代码来源:jsoniq.cpp


示例17: error_example_4

bool
error_example_4(Zorba* aZorba)
{
  MyDiagnosticHandler lHandler;

  try {
    // move this outside if constant folding is fixed
    XQuery_t lQuery = aZorba->compileQuery("1 div 0"); 

    lQuery->registerDiagnosticHandler(&lHandler);
    std::cout << lQuery << std::endl;
  } catch (ZorbaException const& e) {
    std::cerr << e << std::endl; 
    if ( e.diagnostic().kind() == diagnostic::XQUERY_DYNAMIC )
      return true;
  }

	return false;
}
开发者ID:buchenberg,项目名称:zorba,代码行数:19,代码来源:errors.cpp


示例18: example_4

/**
 * Test accessing a non-existent JSONArray member
 */
bool
example_4(Zorba* aZorba)
{
  Iterator_t lIterator, lMembers;
  XQuery_t lQuery = aZorba->compileQuery("[ 1, 2, 3 ]");
  lIterator = lQuery->iterator();
  lIterator->open();
  Item lItem;
  lIterator->next(lItem);

  Item lNonMember = lItem.getArrayValue(4);
  lIterator->close();

  if (!lNonMember.isNull()) {
    return false;
  }

  return true;
}
开发者ID:zorba-processor,项目名称:zorba,代码行数:22,代码来源:jsoniq.cpp


示例19: example_3

/**
 * Test accessing a JSONObject's values directly by name
 */
bool
example_3(Zorba* aZorba)
{
  Iterator_t lIterator;
  XQuery_t lQuery = aZorba->compileQuery("{ \"one\" : 1, \"two\" : 2 }");
  lIterator = lQuery->iterator();
  lIterator->open();
  Item lItem;
  lIterator->next(lItem);

  Item lValue;
  lValue = lItem.getObjectValue("one");
  std::cout << lValue.getLongValue() << std::endl;
  lValue = lItem.getObjectValue("two");
  std::cout << lValue.getLongValue() << std::endl;

  lIterator->close();

  return true;
}
开发者ID:zorba-processor,项目名称:zorba,代码行数:23,代码来源:jsoniq.cpp


示例20: example_2

/**
 * Test accessing a JSONArray's members directly by index
 */
bool
example_2(Zorba* aZorba)
{
  Iterator_t lIterator;
  XQuery_t lQuery = aZorba->compileQuery("[ 1, 2, 3 ]");
  lIterator = lQuery->iterator();
  lIterator->open();
  Item lItem;
  lIterator->next(lItem);

  Item lMember;
  for (int i = 1; i <= 3; i++) {
    lMember = lItem.getArrayValue(i);
    std::cout << lMember.getLongValue() << std::endl;
  }

  lIterator->close();

  return true;
}
开发者ID:zorba-processor,项目名称:zorba,代码行数:23,代码来源:jsoniq.cpp



注:本文中的XQuery_t类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ XSLImportRule类代码示例发布时间:2022-05-31
下一篇:
C++ XPathResult类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap