I am working on a parser to get data from an XML file. I am using libxml2 to extract data. I am a not able to get the attributes from nodes. I only found nb_attributes
to get the count of the attributes.
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
I think joostk meant attribute->children, giving something like this:
See if that works for you.
Try something like:
I think I found why you only got 1 attribute (at least it happened to me).
The problem was that I read attributes for first node but next is a text node. Don't know why, but node->properties gives me a reference to a non-readable part of memory, so it crashed.
My solution was to check node type (element is 1)
I'm using a reader, so:
The entire code you can get it from http://www.xmlsoft.org/examples/reader1.c and add this
to line 50.
The easiest way I found using libxml2 (through libxml++ in C++) was to use the
eval_to_XXX
methods. They evaluate an XPath expression, so you need to use the@property
syntax.For example:
if you just want a single attribute, use xmlGetProp or xmlGetNsProp
If you use SAX method startElementNs(...), this function is what you are looking for:
Usage: