Comments (2)
Maybe I'm missing something, but parse_ws_pcdata
is exactly what you need here.
Quick example:
#include "pugixml.hpp"
#include <stdio.h>
void display(pugi::xml_node node, int depth = 0)
{
for (int i = 0; i < depth; ++i)
printf(".");
if (node.type() == pugi::node_element)
{
printf("element %s", node.name());
}
else if (node.type() == pugi::node_pcdata)
{
printf("pcdata ");
for (const char* str = node.value(); *str; ++str)
printf("0x%02X ", (unsigned char)*str);
}
printf("\n");
for (pugi::xml_node child : node.children())
display(child, depth + 1);
}
int main()
{
const char* xml = R"(
<doc>
<sub>
text
</sub>
</doc>
)";
pugi::xml_document doc;
pugi::xml_parse_result res = doc.load_string(xml, pugi::parse_default | pugi::parse_ws_pcdata);
printf("%s\n", res.description());
display(doc);
}
Output:
No error
.element doc
..pcdata 0x0A
..element sub
...pcdata 0x0A 0x74 0x65 0x78 0x74 0x0A
..pcdata 0x0A
As you can see, doc
has three children, two of them are PCDATA with a single newline.
from pugixml.
You're right! :)
I was mislead with my real test which had PI too. Looks like there are no PCDATA kept in between PI and elements or between multiple successive PIs. I will re-assemble a more complete and real-life sample and build from there. Anyway, I overlooked the side issue that I will not be able to control whitespace like eol around closing tags. The whole idea of relying on a DOM parser to modify the content (namespace updates and attributes sorting) and then output the required canonicalized form, is probably wrong.
This issue should be closed I think.
Thank you Arseny.
from pugixml.
Related Issues (20)
- Empty text childs increase XML file size HOT 5
- xml_node_iterator should satisfy at least std::input_or_output_iterator concept HOT 3
- Assertion fails during number-to-string conversion if wrong C locale is set (non-MSVC) HOT 1
- Support std::filesystem::path HOT 2
- Version 1.14 HOT 1
- Can you add the ability to access child nodes using index? HOT 1
- PUGIXML_WCHAR_MODE and error messages. HOT 1
- add xml_node_type_str function for debugging and application logging HOT 3
- option to join multiple CDATA sections into one when parsing HOT 2
- parse_embed_pcdata and parse_merge_pcdata don't play together HOT 2
- Unexpected #endif in line 13201 with precompilation in a pch.h file HOT 2
- Warning when building 1.14 in x86 on Clang HOT 3
- Position of the parse result offset in case of status_bad_start_element
- Error in handling loading errors example HOT 1
- Incorrect result of xml_document::load_file -"File was not found" HOT 2
- Question: I have made my own case insensitive version, is that ok? HOT 2
- Serilisation HOT 4
- pugi::xml_node and std::ranges, maybe a documentation request HOT 2
- call function xml_node::empty() always return false in anyway HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pugixml.