Pep said:
Erm, I think you miss the point here.
That's what I thought, because I couldn't really see what
your problem was...
No I'm not implying or suggesting that xerces does not
have a dom parser, rather I don't see a easy way of
traversing a tree with it and I admit this may well be my
inexperience with the library.
....on the other hand, maybe not. Is there any specific
problem you're having with DOM tree traversal as
implemented in xerces-c++? As I said, DOM might *seem* a
bit cumbersome, and, well, I suppose it *is* a bit on the
cumbersome side, but can you be a bit more specific on what
gives you trouble with traversing the tree?
As for you ripping apart what is obviously pseudo code
supplied by me to illustrate the simple task I want to
perform, I don't get your point.
My point wasn't really anything about your pseudo-code, but
rather that I perceive a problem with your way of thinking
about XML processing. Naturally, I might be mistaken, my
opinion being based solely on the code and comments you
posted...
Irrespective of whether the data is in a tree format or
not, xml does indeed have data in the form of key pairs
and it is simply the key pairs I want to deal with not the
whole tree structure.
There's no 'whether'. Any XML document represents a tree.
You could, indeed, say that nodes are 'key-data' pairs, but
only if you fully understand that in case of element
nodes 'data' is always a list of nodes. Now that I think
about it, there are no explicit keys, so you couldn't even
say that.
Okay, I guess I just might be on the wrong level of
abstraction here and that causes misunderstanding. If
you're talking about documents similar to:
<document>
<data key="foo">bar</data>
<data key="baz">quux</data>
<etc/>
</document>
....then my point would be that you probably don't need
actual traversal anymore as soon as you reach one of
the 'data' elements. getAttributeNS() and getTextContent()
should do anyway, since you would know the semantics of
data elements.
As it happens I have now looked at the libxml2 class and
found i can quickly traverse the tree in a less complex
manner than I had to follow with the xerces library,
though this is probably because the documentation is
slightly better.
Whatever works for you. libxml2 is certainly workable, and I
don't believe there are any significant limitations. There
are just two points against it I think: it doesn't
implement the W3C DOM API (although I think there was an
adapter of sorts, developer separately from libxml2 itself)
and it's written in C (but that's probably irrelevant in
your case).
So in using the libxml2 class I can quickly get to the
data that I want which is in a crude key/pair format i.e.
<Cat ID="1" >
<CatName>Models</CatName>
</Cat>
Oh yeah, I thought I was missing something. Wrong level of
abstraction. I thought you were perceiving nodes themselves
as key-value pairs.
Which crudely gives key pair ID:1 from the <Cat> element
and text:Models from the <CatName> element. Admittedly I
have to do a little processing in order to derive the
key/pair data entities I want but I get the end result.
Well, it would work the same way with xerces-c++. I suppose
libxml2 is a bit more light-weight, but in my eyes that is
offset by it being non-standard. YMMV.
So like i said, I don't see your point in trying to
analyse someones pseudo code with the attempt to imply the
notation of key/pair as being "fishy"?
If you *represent* key-value pairs in XML that is perfectly
okay I suppose. What I was objecting to was perceiving
nodes as key-value pairs. Just a bit of misunderstanding,
as I said.