diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-01-28 21:12:32 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-01-28 21:43:49 -0800 |
commit | 7aff4d70a62f9f91904e2bd6a574fa44aadbaf64 (patch) | |
tree | 253d6fe8f31e0d64d08199bceb4148bf01a9c003 /parse-xml.c | |
parent | a1dfae87ae6048b82e91112d3d992c472b49b7a2 (diff) | |
download | subsurface-7aff4d70a62f9f91904e2bd6a574fa44aadbaf64.tar.gz |
parse-xml: allow XML nodes with empty tag names
They happen for CDATA content, where libxml2 turns the CDATA fields into
a child of the parent entry, but without a name.
Now, of course, any sane person would just want to use the CDATA as the
string value of the parent itself, but libxml2 probably does this
insanity for a reason. And the reason is probably that some misguided
people want to *write* XML using libxml2, and then the stupid child node
actually acts as a "now I want you to write this data as CDATA".
Whatever the reason, let's just ignore it. We will just traverse such a
nameless child and be happy, and we'll give the nameless child the name
of the parent. Our XML node matching logic will then never see this
insane nameless child at all, and doesn't have to care.
Our whole XML parsing rule-of-thumb is to take the whole "be strict in
what you output, but generous in what you accept" to its logical
conclusion. Because we will literally accept almost anything, in any
format. You can mix tags or attributes wildly, and youc an use CDATA or
not as you see fit. We just don't care.
We're the honeybadger of the divelog world.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'parse-xml.c')
-rw-r--r-- | parse-xml.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/parse-xml.c b/parse-xml.c index 765843fbc..30b616324 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -1350,7 +1350,7 @@ static void visit_one_node(xmlNode *node) return; /* Don't print out the node name if it is "text" */ - if (!strcmp(node->name, "text")) + while (!node->name || !strcmp(node->name, "text")) node = node->parent; name = nodename(node, buffer, sizeof(buffer)); @@ -1438,6 +1438,11 @@ static void traverse(xmlNode *root) for (n = root; n; n = n->next) { struct nesting *rule = nesting; + if (!n->name) { + visit(n); + continue; + } + do { if (!strcmp(rule->name, n->name)) break; |