标签: rapidxml

RapidXML提供空的CDATA节点

我编写了下面的代码来获取CDATA节点值,我得到了节点的名称,但值是空白的.

我将解析Flags更改为parse_full,但它也没有用.

如果我从XML中手动删除"<![CDATA ["和"]]>",它会按预期提供值,但在解析之前删除它不是一个选项.

代码:

#include <iostream>
#include <vector>
#include <sstream>
#include "rapidxml/rapidxml_utils.hpp"

using std::vector;
using std::stringstream;
using std::cout;
using std::endl;

int main(int argc, char* argv[]) {

    rapidxml::file<> xmlFile("test.xml");
    rapidxml::xml_document<> doc;
    doc.parse<rapidxml::parse_full>(xmlFile.data());

    rapidxml::xml_node<>* nodeFrame = doc.first_node()->first_node()->first_node();

    cout << "BEGIN\n\n";

    do {

        cout << "name:  " << nodeFrame->first_node()->name() << "\n";
        cout << "value: " << nodeFrame->first_node()->value() << "\n\n";


    } while( nodeFrame = nodeFrame->next_sibling() );

    cout << "END\n\n";

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

XML:

<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0" xmlns:c="http://base.google.com/cns/1.0">
<itens>
   <item>
    <title><![CDATA[Title 1]]></title>  
    <g:id>34022</g:id>
    <g:price>2173.00</g:price> …
Run Code Online (Sandbox Code Playgroud)

c++ rapidxml c++11

3
推荐指数
1
解决办法
1481
查看次数

Rapidxml 正在写入错误的字符

我最近一直在使用 Rapidxml 并遇到以下问题。当我尝试添加属性时,这些属性不是硬编码的,而是在程序运行时生成的,rapidxml 插入了错误的字符。

这是我的代码示例:

   void ProcessInfo::retriveInfo()
{
    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

   PROCESSENTRY32 pe = { sizeof(pe) };  
   BOOL fOk = ProcessFirst( &pe, hSnapshot );

   using namespace rapidxml;
   xml_document<> doc;

   xml_node<>* decl = doc.allocate_node(node_declaration);
   decl->append_attribute(doc.allocate_attribute("version", "1.0"));
   decl->append_attribute(doc.allocate_attribute("encoding", "utf-8"));
   doc.append_node(decl);

   xml_node<>* root = doc.allocate_node(node_element, "rootnode");

   while(fOk)
   {
       std::string processFile = pe.szExeFile;

   xml_node<>* processName = doc.allocate_node(node_element, PROCESS_NODE);
       root->append_node( processName );


       processName->append_attribute(doc.allocate_attribute( PROCESS_NAME, processFile.c_str() ) );

       char szPID[PID_BUFFER];
       memset(szPID, 0x00, sizeof(szPID) );
       itoa(pe.th32ProcessID, szPID, 10 );
       processName->append_attribute(doc.allocate_attribute( PROCESS_ID, szPID ));

       char szParentPID[PID_BUFFER]; …
Run Code Online (Sandbox Code Playgroud)

c++ xml rapidxml

2
推荐指数
1
解决办法
2875
查看次数

RapidXML:无法打印 - 编译时错误

我正在尝试使用 C++ 应用程序中的 RapidXML 库在控制台中打印 XML 文档数据。

\n\n

我正在关注此处的 RapidXML 手册链接,但出现编译时错误。

\n\n

这是我的 C++ 代码:

\n\n
#include <iostream>\n#include "rapidxml.hpp"\n#include "rapidxml_utils.hpp"\n#include "rapidxml_print.hpp"\n\nint main() {\n    rapidxml::file<> xmlFile("beerJournal.xml");\n    rapidxml::xml_document<> doc;\n    doc.parse<0>(xmlFile.data());\n\n    std::cout << doc;\n\n    return 0;\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

这是错误:

\n\n
rapidxml_print.hpp:115: error: \xe2\x80\x98print_children\xe2\x80\x99 was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]\n                 out = print_children(out, node, flags, indent);\n                       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~\n\nrapidxml_print.hpp:169: \xe2\x80\x98template<class OutIt, class Ch> OutIt rapidxml::internal::print_children(OutIt, const rapidxml::xml_node<Ch>*, int, int)\xe2\x80\x99 declared here, …
Run Code Online (Sandbox Code Playgroud)

c++ xml printf rapidxml cout

2
推荐指数
1
解决办法
746
查看次数

RapidXML 保存到文件中

我用谷歌搜索了一下,在将xml_document<>文档保存在.xml文件中时遇到问题。这段代码将把Chess Games Notations 保存为 XML 文件,我将把它放入一个压缩文件中,以便向其中添加多媒体文件。因此,有人可以为 XML 中存储的每个游戏添加音频评论。

#ifndef _FILEREADER_HPP
#define _FILE_READER_HPP

#include<fstream>
#include"rapidxml.hpp"
#include"Notation.h"


namespace pgnx
{
    class FileWriter
    {
        std::map<unsigned int, Tournament> data;
        std::ofstream file;
        std::string fn;
        rapidxml::xml_document<> doc;
    protected:
        void save();
    public:
        FileWriter(char* filename);
        FileWriter();
        ~FileWriter(){}
        void prepare();
        void insertTournament(Tournament);
        //Operators
        FileWriter& operator+(Tournament rhs);
        FileWriter& operator=(std::map<unsigned int, Tournament> rhs);
        FileWriter& operator=(pgnx::FileWriter rhs);
        Tournament& operator[](unsigned int index);
    };
}

#endif
Run Code Online (Sandbox Code Playgroud)

和功能

void FileWriter::prepare()
{
    using namespace rapidxml;
    xml_node<>* decl = doc.allocate_node(node_declaration);
    decl->append_attribute(doc.allocate_attribute("version", "1.0"));
    decl->append_attribute(doc.allocate_attribute("encoding", …
Run Code Online (Sandbox Code Playgroud)

rapidxml visual-c++

1
推荐指数
1
解决办法
5550
查看次数

boost/rapidxml解析崩溃

我们在pub/sub代理实现中使用boost/rapidxml进行XML解析,对于某个XML有效负载,代理崩溃了.

为了消除尽可能多的变量,我实现了一个只执行XML解析的简短测试程序,崩溃类似.

我的简短测试程序在这里找到:

#include <stdio.h>       // printf
#include <unistd.h>      // read
#include <sys/types.h>   // open
#include <sys/stat.h>    // open
#include <fcntl.h>       // open
#include <errno.h>       // errno
#include <string.h>      // strerror
#include "rapidxml.hpp"
#ifdef LONG_RAPIDXML_NAME_SPACE
// boost version >= 1.45
using namespace boost::property_tree::detail::rapidxml;
#else
// boost version <= 1.44
using namespace rapidxml;
#endif
/* ****************************************************************************
*
* xmlTreePresent -
*/
static void xmlTreePresent(xml_node<>* nodeP, std::string indent, int depth = 0)
{
    static int callNo = 0;
    ++callNo;
    if(nodeP == NULL) …
Run Code Online (Sandbox Code Playgroud)

c++ boost rapidxml

1
推荐指数
1
解决办法
1013
查看次数

RapidXML从文件中读取 - 这里有什么问题?

这两种读取输入文件的方法有什么区别?

1)使用 'ifstream.get()'

2)使用vector<char>with ifstreambuf_iterator<char> (我不太了解!)

(除了使用漂亮的矢量方法的明显答案)

输入文件是XML,如下所示,立即解析为rapidxml文档.(在其他地方初始化,参见示例main函数.)

首先,让我向您展示两种编写'load_config'函数的方法,一种使用ifstream.get(),一种使用vector<char>

方法1 ifstream.get()提供了工作代码和一个安全的rapidXML文档对象:

rapidxml::xml_document<> *load_config(rapidxml::xml_document<> *doc){
   ifstream myfile("inputfile");

   //read in config file
   char ch;
   char buffer[65536];
   size_t chars_read = 0;

   while(myfile.get(ch) && (chars_read < 65535)){
      buffer[chars_read++] = ch;
   }
   buffer[chars_read++] = '\0';

   cout<<"clearing old doc"<<endl;
   doc->clear();

   doc->parse<0>(buffer);

   //debug returns as expected here
   cout << "load_config: Name of my first node is: " << doc->first_node()->name() << "\n";

   return doc;
}
Run Code Online (Sandbox Code Playgroud)

方法2导致另一个库的cloberred rapidXML文档 - 特别是对curl_global_init(CURL_GLOBAL_SSL)的调用[参见下面的主要代码] - 但我还没有把它归咎于curl_global_init. …

c++ file-io rapidxml code-formatting libcurl

0
推荐指数
1
解决办法
3840
查看次数

标签 统计

rapidxml ×6

c++ ×5

xml ×2

boost ×1

c++11 ×1

code-formatting ×1

cout ×1

file-io ×1

libcurl ×1

printf ×1

visual-c++ ×1