How to Read All Attributes of an Element in VTD-XML?

There are two ways to read all the attribute values of an element node.

The first one is to use XPath expression  @* as in the example below
  ap = new AutoPilot (vn);
  ap.selectXPath(“@*”);
  int i=-1;
while((i=ap.evalXPath())!=-1){
      // i will be attr name, i+1 will be attribute value
   } 

  

The second is lighter weight, which is by directly using autoPilot’s selectAttr() and iterAttr()
ap = new AutoPilot(vn);
ap.selectAttr(“*”);
int i=-1;
while((i=ap.iterateAttr())!=-1){
 // i will be attr name, i+1 will be attribute value
}
Advertisements

4 comments so far

  1. berkerley on

    what if I want to have one element’s all attribute values read into a linkedlist and have that element’s sibling’s all attribute values read into another linkedlist? How can i implement this requirement? looking forward to your reply!

    • jimmyzhang on

      how to construct a list is not something vtd-xml offers, you have to do it yourself. To access all attributes, just instantiate autoPilot and select attr() and iterateAttr()

  2. Wout on

    Is this possible with extended VTD-XML as well? As far as I can see those methods are protected in AutoPilotHuge…

    • jimmyzhang on

      of course, why not?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: