• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            牽著老婆滿街逛

            嚴(yán)以律己,寬以待人. 三思而后行.
            GMail/GTalk: yanglinbo#google.com;
            MSN/Email: tx7do#yahoo.com.cn;
            QQ: 3 0 3 3 9 6 9 2 0 .

            Quick notes on how to use RapidXML

            轉(zhuǎn)載自:http://www.ffuts.org/blog/quick-notes-on-how-to-use-rapidxml/

            There’s a C++ XML library called RapidXML which is perfect for most non-enterprise uses of XML. I wouldn’t call this a tutorial, but I hope this ends up helping someone. The documentation isn’t very explicit on how to output an XML declaration, for example.

            How to create your XML from scratch and then output this XML into a string, with an XML declaration:

            <?xml version="1.0" encoding="utf-8"?>
            <rootnode version="1.0" type="example">
             
            <childnode/>
            </rootnode>
            using namespace rapidxml;

            xml_document
            <> doc;

            // xml declaration
            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);

            // root node
            xml_node
            <>* root = doc.allocate_node(node_element, "rootnode");
            root
            ->append_attribute(doc.allocate_attribute("version", "1.0"));
            root
            ->append_attribute(doc.allocate_attribute("type", "example"));
            doc
            .append_node(root);

            // child node
            xml_node
            <>* child = doc.allocate_node(node_element, "childnode");
            root
            ->append_node(child);

            std
            ::string xml_as_string;
            // watch for name collisions here, print() is a very common function name!
            print(std::back_inserter(xml_as_string), doc);
            // xml_as_string now contains the XML in string form, indented
            // (in all its angle bracket glory)

            std
            ::string xml_no_indent;
            // print_no_indenting is the only flag that print() knows about
            print(std::back_inserter(xml_as_string), doc, print_no_indenting);
            // xml_no_indent now contains non-indented XML


            Parsing and traversing an XML document like this one:

            <?xml version="1.0" encoding="utf-8"?>
            <rootnode version="1.0" type="example">
             
            <childnode entry="1">
               
            <evendeepernode attr1="cat" attr2="dog"/>
               
            <evendeepernode attr1="lion" attr2="wolf"/>
             
            </childnode>
             
            <childnode entry="2">
             
            </childnode>
            </rootnode>
            void traverse_xml(std::string input_xml)
            {
               
            // (input_xml contains the above XML)

               
            // make a safe-to-modify copy of input_xml
               
            // (you should never modify the contents of an std::string directly)
                vector
            <char> xml_copy(input_xml.begin(), input_xml.end());
                xml_copy
            .push_back('\0');

               
            // only use xml_copy from here on!
                xml_document
            <> doc;
               
            // we are choosing to parse the XML declaration
               
            // parse_no_data_nodes prevents RapidXML from using the somewhat surprising
               
            // behavior of having both values and data nodes, and having data nodes take
               
            // precedence over values when printing
               
            // >>> note that this will skip parsing of CDATA nodes <<<
                doc
            .parse<parse_declaration_node | parse_no_data_nodes>(&xml_copy[0]);

               
            // alternatively, use one of the two commented lines below to parse CDATA nodes,
               
            // but please note the above caveat about surprising interactions between
               
            // values and data nodes (also read http://www.ffuts.org/blog/a-rapidxml-gotcha/)
               
            // if you use one of these two declarations try to use data nodes exclusively and
               
            // avoid using value()
               
            //doc.parse<parse_declaration_node>(&xml_copy[0]); // just get the XML declaration
               
            //doc.parse<parse_full>(&xml_copy[0]); // parses everything (slowest)

               
            // since we have parsed the XML declaration, it is the first node
               
            // (otherwise the first node would be our root node)
               
            string encoding = doc.first_node()->first_attribute("encoding")->value();
               
            // encoding == "utf-8"

               
            // we didn't keep track of our previous traversal, so let's start again
               
            // we can match nodes by name, skipping the xml declaration entirely
                xml_node
            <>* cur_node = doc.first_node("rootnode");
               
            string rootnode_type = cur_node->first_attribute("type")->value();
               
            // rootnode_type == "example"

               
            // go straight to the first evendeepernode
                cur_node
            = cur_node->first_node("childnode")->first_node("evendeepernode");
               
            string attr2 = cur_node->first_attribute("attr2")->value();
               
            // attr2 == "dog"

               
            // and then to the second evendeepernode
                cur_node
            = cur_node->next_sibling("evendeepernode");
                attr2
            = cur_node->first_attribute("attr2")->value();
               
            // now attr2 == "wolf"
            }

            posted on 2010-08-18 02:35 楊粼波 閱讀(1240) 評(píng)論(3)  編輯 收藏 引用

            評(píng)論

            # re: Quick notes on how to use RapidXML 2010-08-18 20:29 dayforever

            記得修改allocstring函數(shù),將最后一個(gè)字符設(shè)置為'\0',不然死很難看
            記得使用前先看看對(duì)應(yīng)flag的意思,不然死的很難看  回復(fù)  更多評(píng)論   

            # re: Quick notes on how to use RapidXML 2010-08-18 20:30 dayforever

            記得所有的value都必須是常量字符串或者是allocstring出來的,不然死的很難看  回復(fù)  更多評(píng)論   

            # re: Quick notes on how to use RapidXML 2010-08-23 20:49 楊粼波

            不明白……  回復(fù)  更多評(píng)論   


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            66精品综合久久久久久久| 99精品久久精品| 久久精品国产国产精品四凭 | 久久r热这里有精品视频| 色偷偷88888欧美精品久久久| 亚洲精品无码久久久久AV麻豆| 国产 亚洲 欧美 另类 久久| 国产精品无码久久综合| 久久精品蜜芽亚洲国产AV| 久久婷婷五月综合色奶水99啪| 亚洲AV日韩精品久久久久久| 中文字幕久久精品无码| 久久婷婷五月综合97色| 97久久国产亚洲精品超碰热| 久久r热这里有精品视频| 亚洲天堂久久精品| 久久久久久久综合综合狠狠| 一极黄色视频久久网站| 日本五月天婷久久网站| 色综合久久久久综合体桃花网| 久久天天躁狠狠躁夜夜网站| 狠狠狠色丁香婷婷综合久久五月| 久久国产精品久久国产精品| 国产精品美女久久久久AV福利| 青青草国产97免久久费观看| 久久人做人爽一区二区三区| 久久久精品国产sm调教网站| 嫩草影院久久国产精品| 久久精品国产99国产电影网| 亚洲成人精品久久| 亚洲欧洲精品成人久久曰影片| 久久久久久久女国产乱让韩| 99精品久久精品| 午夜精品久久久久久影视777| 欧美精品久久久久久久自慰| 老司机国内精品久久久久| 美女久久久久久| 国内精品人妻无码久久久影院| 久久久久国产视频电影| 日韩久久久久久中文人妻 | 色8激情欧美成人久久综合电|