Re: [xml] find out wether a node is a leaf or contains other elements

On Tue, Jun 07, 2005 at 11:40:15AM +0200, "klemens letulé" wrote:
I just started to use libxml and am already stuck. The question is more
less in the subject. I want to restrict the deletion of nodes who have
child elements.

  Have you read the docs ?
No child element may mean various things, your question is ambiguous.
Node->children == NULL might be the test you want ... or not.


Yes, i read the docs... maybe it was too much input in a short time! 

  Take your time and don't rush. It's like asking questions on a nuclear
physic mailing list without having taken the time to read and digest
the basic science around it.

I try to make it more clear what i want. As an element i mean now an
element as in the DTD.

<!ELEMENT fw-input-rule (action, protocol, from-ip, from-port, to-ip,
to-port, log)>
<!ELEMENT action (#PCDATA)>
<!ELEMENT protocol (#PCDATA)>
<!ELEMENT from-ip (#PCDATA)>

So it should be possible to delete a "fw-input-rule node" but not an 
"action node".

Is there an easy way to distinguish between elements who have other "child 
elements" and elements who are just a leaf?

  Your questions are confusing, you mix content model and actual tree.
I can't answer your question it's too undefined. Where are those DTD
declarations ? External DTD subset are not loaded by default. The 
content field of the nodes may be usable or not. And your question is
not precise enough to answer
have different model, I can't tell what you're considering.

  Did you try xmllint --debug on some of those tree to get an idea of
what the structure looks like ? You must experiment because there is 
no way I can dump the needed informations in your brain instantly. There is
a learning curve, then you will be able to ask clearer questions.


Daniel Veillard      | Red Hat Desktop team
veillard redhat com  | libxml GNOME XML XSLT toolkit | Rpmfind RPM search engine

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