VTD-XML Tutorial (0)

Classes/Interfaces and Methods (类、接口,方法)

Important Classes/Interfaces (关键类、接口)

Essential Classes (基本类)

VTD Generator: VTDGen is the class that encapsulates the main parsing, index loading and index reading functions.(VTDGen是一个封装了主解析,索引加载以及索引读取等方法的类)


VTD Navigator: VTDNav is the class that encapsulates XML, VTD, and hierarchical info contains various navigation functions performs various comparison and VTD to string or numerical data conversion functions. (VTDNav类封装了XML,VTD以及分层信息, 包含了多种的导航函数用来执行各种VTD到String / numerical 数据的转换方法)


Autopilot: A class containing functions that perform node-level iteration and XPath. (一个包含了结点迭代 和XPath函数的类)


XMLModifier: A class that takes advantage of VTD-XML's incremental update capability. (一个拥有VTD-XML增量更新的类)


Other Classes/Interfaces

ILongBuffer: This is the interface for VTD record container.


FastLongBuffer: This class implements ILongBuffer interface. Under the hood, it is a chunk-based buffer that will grow automatically.


NodeRecorder: Save the node location.


BookMark: A hashable, comparable way of saving a single copy of cursor position.


TextIterator: This class allows one to access text nodes in a mix-content document.


ParseException: The root class for any exception conditions during parse


NavException: The root class for any exceptions during navigation


XPathEvalException: Thrown when there is something during XPath evaluation


XPathParseException: Thrown when an error occurred during the construction of XPathExpr


XMLModiferException: Thrown when there is an exception condition during the modification of XML document.


Member methods of VTDNav

In this sub-section, we categorize and selectively annotate member methods of VTDNav.

Methods designed for hierarchical view of VTD

Navigate the cursor

boolean toElement(int direction);
boolean toElement(int direction, String elementName);
boolean toElementNS(int direction, String URL, String local_name);


About the element at the cursor position

int getCurrentIndex()                    // return the VTD index of the current element
int getCurrentDepth()                    // return depth of current element
boolean matchElement(String s);    // match the element name (of the cursor) against a string value
boolean matchElementNS(String s); // match the element name (name space aware)
boolean matchTokens(int i1,VTDNav vn1, int i2);     // match the element name (name space aware)

Attributes, Text, and CDATA

int getAttrVal(String attrName);
int getAttrValNS(String URL, String localName);
boolean hasAttr(String attrName);
boolean hasAttrNs(String URL, String localName);
int getText()            // return the index value of the text value (character data or CDATA), -1 if none found

Helper function

void push();

boolean pop();

Address an element fragment

* long getElementFragment(); // get the length and offset of the element fragment;

                             // upper 32 bits length lower 32 bits offset



Methods for individual VTD records

Comparison

boolean matchRawTokenString(int, String); // Match the token against a string, entities and cha
                                  // references are not resolved
boolean matchTokenString(int, String); // match the token against a string, entities and char
                               // references are resolved
boolean matchTokens(int i1, VTDNav vn2,int i2) // match two VTD tokens

int compareRawTokenString(int, String); //lexically compare a VTD token with a string, returns 1, 0 or -1
int compareTokenString(int, String); //lexically compare a VTD token with a string, returns 1, 0 or -1
int compareTokens(int, VTDNav vn2, int); // lexically compare two VTD tokens
                                                                        

Query token parameters

int getTokenDepth(int index);
int getTokenLength(int index);
int getTokenOffset(int index);
int getTokenType(int index);


Token to String conversion

String toRawString(int index);            // entities and char references not resolved
String toString(int index);                  // entities and char reference resolved
String toNormalizedString(int index);  // Normalized


Tokens to numerical data conversion

int parseInt(int index);
long parseLong(int index);
float parseFloat(int index);
double parseDouble(int index);


Properties of XML and VTD

int getRootIndex();                   // Return the VTD index for the root element
IByteBuffer getXML();                // Get the document buffer
int getTokenCount();                 // Get the total number of VTD tokens
 

Methods for writing/loading index

Index writing

void writeIndex(OutputStream os);
void writeIndex(String FileName);


Index loading


VTDNav loadIndex(InputStream is);
VTDNav loadIndex(String FileName);
VTDNav loadIndex(byte[] ba);


Methods of AutoPilot for Doing Node Iteration

Select Elements

void selectElement(String elementName); // select element name before iterating
void selectElementNS(String URL, String elementName);       // the namespace aware version


Iterate the nodes

boolean iterate();


Methods of AutoPilot for XPath

Select XPath

void declareXPathNameSpace(String attrName);
void selectXPath(String XPathExpr);    // compile the XPath string

Evaluate XPath

int evalXPath();  // evaluate XPath and moves the cursor to various locations of the document
double evalXPathToNumber(); // evaluate XPath to a double
String evalXPathToString();  //evaluate XPath to a string
boolean evalXPathToBoolean(); // evaluate XPath to a boolean


Other Methods

 

void resetXPath();      // call this function will reset the internal state of XPath for reuse
void bind(VTDNav vn); //bind  VTDNav to an autoPilot

Methods for XMLModifier

Remove

void remove()
void removeAttribute(String attrName)
void removeToken(int i)

Insert

void insertAfterElement(String s)
void insertAfterElement(byte[] ba)
void insertBeforeElement(String s)
void insertBeforeElement(byte[] ba)
void insertAttribute(String s);
void insertAttribute(byte[] ba);



Update

void updateToken(byte[] b);
void updateToken(String s);

Other Methods

output(OutputStream os);
reset()



你可能感兴趣的:(XML)