Re: [xml] C API question: reading attribute name?



Daniel Veillard wrote:
On Tue, May 10, 2005 at 07:33:43PM -0500, Jeremy Enos wrote:
  
I am a beginner with libxml, and I have a problem which hours of 
searching through the API documentation hasn't been able to help with.

If I have a file which contains:

<?xml version="1.0"?>
<foo bar="blah">
   <t1>text</t1>
</foo>

How do I get the attribute name "bar"?  I'm able to get the value of bar 
(blah) using xmlTextReaderGetAttribute(), but I can't seem to find a way 
to print out the attribute name itself (bar).
    

  This sounds a lot like
  http://mail.gnome.org/archives/xml/2004-October/msg00101.html

I think the solution is explained at
  http://xmlsoft.planetmirror.com/xmlreader.html#Extracting1
You can either:
  - loop with for all values of 0 .. AttributeCount() - 1
    and use MoveToAttributeNo(no) then use Name()/Prefix()/NamespaceUri()...
  - or use MoveToNextAttribute()
    and similary use Name()/Prefix()/NamespaceUri()

 the small Python example in that doc shows the second one.

I did not design this API, this is directly copied from C# xmlReader API.

  
Is it possible using C bindings?
    

  Hum, there is no "bindings" for C as the API is C. all this can be done
at the C level.


  
Right... that exposes my terminology weakness as a newbie. In any case, the mail you pointed me to seemed to be the same problem, and prescribed:
I believe all you need to do is fetch a pointer to first attribute
("property"), and then simply use ->next in order to cycle through the
attribute list. 
However, I don't know a way to acquire a pointer to the first attribute property.
thx-

    Jeremy



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