Re: iterating NodeList::iterator gives "Text" nodes



When I wrote my answer, I must have forgotten the last part of your question. (When is each node type used?)
I don't think that's described very well anywhere. The descriptions in the reference documentation are extremely short. The tutorial (https://developer.gnome.org/libxml++-tutorial/stable/chapter-parsers.html) only shows the inheritance hierarchy (not fully updated) with no further explanation. Each leaf in the inheritance hierarchy corresponds to a value of enum xmlElementType in the underlying C package, libxml2, but that's also very briefly documented.

You can probably get some feeling for the node types by experimenting with some of the example programs, e.g.
https://git.gnome.org/browse/libxml++/tree/examples/dom_parser
https://git.gnome.org/browse/libxml++/tree/examples/dom_parse_entities

Kjell

2013-08-31 18:40, Pablo Madoery skrev:
thank you very much. Your answer is really useful for me.


2013/8/30 Kjell Ahlstedt <kjell ahlstedt bredband net>
The text nodes contain the white space between the tags. If you use
  document.write_to_file("file.txt");
instead of
  document.write_to_file_formatted("file.txt");
no white space is added, and there are no text nodes.

I don't think there is any documentation that explains the inheritance hierarchy. Actually I don't think there is much to explain. The inheritance hierarchy has no deeper meaning. It does not correspond to the structure of an xml document. I think it's mostly an attempt to group node types that have something in common.

Kjell

2013-08-29 21:00, Pablo Madoery skrev:
Hello. I have this code and it generate some xml like this:

<?xml version="1.0" encoding="UTF-8"?>
<Scenario>
  <A/>
  <B/>
  <C/>
</Scenario>

When i want to obtain all the childs Elements (A, B, C) i use a list in this way

xmlpp::Node::NodeList list = rootNode->get_children();

for (xmlpp::Node::NodeList::iterator cur = list.begin(); cur != list.end(); ++cur)
{
cout<<(*cur)->get_name()<<endl;
}

when i obtain the list:
text
A
text
B
text
C
text

Why has it TextNodes interleaved with the Nodes i want ?



I dont understand very well the inheritance hierarchy of node types (https://developer.gnome.org/libxml++/stable/classxmlpp_1_1Node.html):
  • xmlpp::Node:
    • xmlpp::Attribute
    • xmlpp::ContentNode
      • xmlpp::CdataNode
      • xmlpp::CommentNode
      • xmlpp::ProcessingInstructionNode
      • xmlpp::TextNode
    • xmlpp::Element
    • xmlpp::EntityReference

    is there some documentation that explains better inheritance hierarchy of node types and when is used each?

    Thank you very much for your time !!!






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]