VTD-XML

xml Add comments

VTD-XML is a flat of original XML processing technologies centralised around a non-extractive XML parsing framework titled Virtual Token Descriptor (VTD). VTD-XML provides interfaces for C, C#, and Java. VTD-XML solves a sort of problems inexplicit with existing DOM and SAX models in a artefact that makes it saint for Service Oriented Architecture (SOA) applications.

Depending on the perspective, VTD-XML crapper be viewed as digit of the following:

  • A “document-centric” XML parser
  • A autochthonous XML indexer or a enter info that uses star accumulation to compound the book XML
  • An incremental XML noesis modifier
  • An XML slicer/splitter/assembler
  • An XML editor/eraser
  • A artefact to opening XML processing onto a chip

VTD-XML is highly module efficient; benchmarks exhibit a exemplary disbursement of exclusive 1.3 to 1.5 nowadays the filler of an XML writing (in bytes) to attain haphazard access. VTD-XML beatniks SAX parsers in benchmarks by a edge of 1.5 to 2.0 nowadays parsing speed. A inform scrutiny the action of C, C#, and Java interfaces is available. In this article, you’ll countenance at the theory behindhand VTD-XML and whatever distribution apps that exhibit soured its prizewinning features.

How It Works

A exemplary DOM parser allocates digit organisation of module for apiece minimal in the XML signaling enter tree. This is expensive in both module action (due to fragmentation) and happening because of the trend abstraction of portion requests. VTD-XML exclusive stores a exact double of the XML in-memory unparsed and then adds an “index” in face of it to earmark for ultimate guidance and access. Because datum an XML enter is by definition a read-only process, it makes significance that you requirement not hit the plasticity of variable-allocation at this saucer in the parsing. Last, ready in nous that VTD-XML is technically a processing help kinda than an API and you crapper physique your possess API on crowning of a VTD-XML model. Through the residual of this article, I’ll shew the XimpleWare feat acquirable from SourceForge.

Making libvtd-xml.lib for Visual Studio 2005

VTD-XML 2.2.1 for C (as liberated on 10/27/2007) includes exclusive makefiles fashioned for Gnu CC (GCC). To physique for Visual Studio 2005, I meet temporary by assembling every the cipher in the directory and shoving it into a library, same this:

del *.lib
lib /out:libvtd-xml.lib arrayList.obj autoPilot.obj
   binaryExpr.obj bookMark.obj contextBuffer.obj
   decoder.obj elementFragmentNs.obj fastIntBuffer.obj
   fastLongBuffer.obj filterExpr.obj funcExpr.obj
   helper.obj indexHandler.obj intHash.obj l8.tab.obj
   lex.yy.obj literalExpr.obj locationPathExpr.obj
   nodeRecorder.obj numberExpr.obj pathExpr.obj
   RSSReader.obj textIter.obj unaryExpr.obj
   unionExpr.obj vtdGen.obj vtdNav.obj XMLChar.obj
   XMLModifier.obj

Hello, VTD-XML!

In the longstanding Computer Science practice of display the simplest doable warning first, you’ll move soured by hunting at the direct C information you crapper fairly indite to parse an XML file. Its task: Echo every the nodes in an XML enter to a stdout stream.

 1 #include “everything.h”
 2 struct exception_context the_exception_context[1];
 3 int main(){
 4    omission e;
 5    VTDGen *vg = NULL;
 6    VTDNav *vn = NULL;
 7    UCSChar *string = NULL;
 8    Try{
 9       vg = createVTDGen();
10       if (parseFile(vg,TRUE,”input.xml”)){
11          vn = getNav(vg);
12          if (toElementNS(vn,FIRST_CHILD,L”someURL”,L”b”)){
13             int i = getText(vn);
14             if (i!=-1){
15                progress = toString(vn,i);
16                wprintf(L”the book convexity continuance is %d ==> %s \n”,
                          i,string);
17                free(string);
18             }
19          }
20          free(vn->XMLDoc);
21       } added {
22          free(vg->XMLDoc);
23       }
24    }Catch(e){    // appendage different types of exceptions here
25    }
26    freeVTDGen(vg);
27    freeVTDNav(vn);
28    convey 0;
29 }

The prototypal movement is to create yourself a VTD Generator happening via createVTDGen() as you do in Line 9. The VTDGen goal parses the DTD but doesn’t hold proclaimed entities. Next, you ingest the VTDGen goal to parse the XML signaling file. Your signaling enter for this effort is befittingly simple:

<ns1:a xmlns:ns1=”someURL”>
   <ns1:b> greeting world! </ns1:b>
</ns1:a>

Listing 1: Input.xml for the greeting program

You then transfer in the signaling name and a alarum indicating whether the parser should be namespace-aware to parseFile(). For cyberspace feeds, much as RSS files, you crapper ingest parseHttpUrl() in a kindred manner, eliminate that you transfer in the “http://..” URI.

Next, you set a VTDnav guidance indicator goal with getNav(); now, you crapper ingest the toElementNS() method to begin traversal. The prototypal constant in toElementNS() signifies the content of movement that crapper be an enumerated continuance ROOT, PARENT, FIRST_CHILD, LAST_CHILD, NEXT_SIBLING, or PREV_SIBLING. The ordinal constant is an URL, which is extraneous for this example. The ordinal and test constant is the namespace of interest, which in the warning is namespace “b” (for example, <ns1:b>)

Assuming the guidance worked, you then crapper call getText() to intend the VTD finger of the book convexity and then toString() to vantage discover the actualised convexity data. In gift with your input.xml, above, the production when separate from the DOS stimulate is:

C:\ximpleware\demo> hello_world.exe
the book convexity continuance is 5 ==>  greeting world!

The full cipher country is enclosed by a Try/Catch macro, an connection of C++ call omission handling, manner of cristal M. Costello’s cexcept.

One Response to “VTD-XML”

  1. Library » Blog Archive » VTD-XML Says:

    [...] Twoostwo wrote an interesting post today on VTD-XMLHere’s a quick excerptTo physique for Visual Studio 2005, I meet temporary by assembling every the cipher in the directory and shoving it into a library, same this: del *. lib lib /out:libvtd-xml. lib arrayList. obj autoPilot. obj binaryExpr. obj bookMark. obj contextBuffer…. [...]

Leave a Reply

Webmaster & Hayalbahcesi by Msn Nickleri
Entries RSS Comments RSS Log in