pugixml

Proper way to parse XML using pugixml

自闭症网瘾萝莉.ら 提交于 2021-02-19 05:35:08
问题 I have an XML file that I need to parse and I'm struggling with using PugiXML to parse out all elements and attributes. I have the following XML file: <?xml version = '1.0' encoding = 'UTF-8'?> <PanelList DefaultTheme="konami" > <Panel xpos="0" ypos="0" width="800" height="600" imagepath="./%THEME%/background_uga_large.png" name="AttractMode0" > <GameViewport xpos="0" ypos="0" width="630" height="526" name="gameviewport"/> <ValueLabel xpos="120" ypos="550" width="448" height="30" fontsize="18

XML parsing with PugiXML, infinite loop

ぐ巨炮叔叔 提交于 2021-02-08 03:36:05
问题 this is pretty much the first C++ program that I ever made, it should display a list of xml nodes in the document. I made an exact same thing work using TinyXML, but I find Pugi much nicer and would like to continue using it. Program code: #include <iostream> #include <string> #include <vector> using namespace std; #include "pugixml/src/pugixml.hpp" #include "pugixml/src/pugiconfig.hpp" #include "pugixml/src/pugixml.cpp" using namespace pugi; const char * identify(xml_node node) { const char

Build an xml tree from scratch - pugixml C++

ぐ巨炮叔叔 提交于 2020-01-12 07:28:06
问题 Firstly I would like to say that I have been using an XML parser written by Frank Vanden Berghen and recently trying to migrate to Pugixml. I am finding the transition bit difficult. Hoping to get some help here. Question: How can I build a tree from scratch for the small xml below using pugixml APIs? I tried looking into the examples on the pugixml home page, but most of them are hard coded with root node values. what I mean is if (!doc.load("<node id='123'>text</node><!-- comment -->", pugi

Prevent duplicate pugixml::xml_node

↘锁芯ラ 提交于 2020-01-05 10:24:14
问题 I'm writing a part of my app that store settings in XML file, but I don't want to 'client' duplicate, I want this: <jack> <client name="something"> <port name="someport" /> <port name="someport_2" /> </client> </jack> But instead I get: <jack> <client name="something"> <port name="someport" /> </client> <client name="something"> <port name="someport_2" /> </client> </jack> thought "just check if node already exists" but that's the problem, so I've this piece of code: // xjack is the root node

pugixml - get all text nodes (PCDATA), not just the first

回眸只為那壹抹淺笑 提交于 2019-12-23 21:26:03
问题 Currently, if I try to parse <parent> First bit of text <child> </child> Second bit of text </parent> I only get First bit of text with parent.text().get() What's the correct way to grab all text nodes in parent ? Is there a nice utility function for this? How could it be done iterating though all children? 回答1: There is no function that concatenates all text; if you want to get a list of text node children, you have two options: XPath query: pugi::xpath_node_set ns = parent.select_nodes(

Remove child nodes from parent - PugiXML

核能气质少年 提交于 2019-12-13 05:51:26
问题 <Node> <A> <B id = "it_DEN"></B> </A> <A> <B id = "en_KEN"></B> </A> <A> <B id = "it_BEN"></B> </A> </Node> How can I remove child node of <A></A> that has child node <B></B> which has attribute id not starts with it using PugiXML. The result would be as below: <Node> <A> <B id = "it_DEN"></B> </A> <A> <B id = "it_BEN"></B> </A> </Node> 回答1: This is slightly tricky if you want to remove nodes while iterating (to keep the code single-pass). Here's one way to do it: bool should_remove(pugi::xml

Read German text from XML and write to a PDF

淺唱寂寞╮ 提交于 2019-12-12 04:33:19
问题 I have an XML (in UTF-8). I have to read a value of a std::string variable from it using PugiXML libraries. After reading the value, I am printing it on console but in my actual project, I have to put that value to a PDF (using LibHaru libraries). My MWE is following: #include <iostream> #include "pugiconfig.hpp" #include "pugixml.hpp" using namespace pugi; int main() { pugi::xml_document doc; pugi::xml_parse_result result = doc.load_file(FILEPATH); xml_node root_node = doc.child("Report");

Namespace usage in XML [duplicate]

霸气de小男生 提交于 2019-12-11 06:36:09
问题 This question already has an answer here : Pugixml - parse namespace with prefix mapping and without prefix mappig (1 answer) Closed 3 years ago . I'm parsing XML using pugi xml, which is not a namespace-aware parser (see Using Boost to read and write XML files). I'm trying to figure out how much of an issue this might be, but the problem is I don't 100% understand what XML namespaces are used for. Here is an example of some XML (that I created) that would be problematic: <Results> <Documents

Map node names using pugixml for different inputs

梦想的初衷 提交于 2019-12-08 10:46:54
问题 Problem My program spits out XML nodes from a file using pugixml . This is the bit of the code which does this: for (auto& ea: mapa) { std::cout << "Removed:" << std::endl; ea.second.print(std::cout); } for (auto& eb: mapb) { std::cout << "Added:" << std::endl; eb.second.print(std::cout); } All nodes spat out should have this format (for example filea.xml): <entry> <id><![CDATA[9]]></id> <description><![CDATA[Dolce 27 Speed]]></description> </entry> However what is spat out depends on how the

Convert pugixml's result.offset to column/line

给你一囗甜甜゛ 提交于 2019-12-07 08:46:07
问题 I need user-friendly error reporting for an application that uses pugixml. I am currently using result.offset. Is there a way to get the line and column instead? I am potentially dealing with large XML files, if that makes a difference. 回答1: This functionality is not readily available in pugixml since it's relatively expensive to do it on every parse, and after parsing is complete it's impossible to recover file/line information in the general case. Here's a snippet that builds an offset ->