Giter Club home page Giter Club logo

Comments (2)

zeux avatar zeux commented on August 26, 2024

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.

omascia avatar omascia commented on August 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.