2006-05-24

BDB XML & document insertion

try {    
  XmlManager mgr( DBXML_ALLOW_EXTERNAL_ACCESS);  // flag is for validation
  XmlContainer cont =mgr.openContainer( "clientlog.dbxml",
                                        DB_CREATE |
                                        DBXML_ALLOW_VALIDATION,
                                        XmlContainer::WholedocContainer);

  XmlDocument newdoc =mgr.createDocument();

  XmlUpdateContext uc =mgr.createUpdateContext();

  XmlInputStream *in =mgr.createStdInInputStream();

  newdoc.setContentAsXmlInputStream( in);

  cont.putDocument(newdoc, uc, DBXML_GEN_NAME);

  ...

BDB XML & Metadata

time_t now = time( 0 );
char timeString[100];

strftime(timeString, 100, "%Y-%m-%dT%H:%M:%S", localtime( &now ) );

newdoc.setMetaData( "", "created", timeString);

Sarissa & XML parsing

function callback( responseText)
{
  var oDomDoc = Sarissa.getDomDocument( );

  oDomDoc = ( new DOMParser()).parseFromString( responseText, "text/xml");
  if( oDomDoc.parseError != 0)
    handle_error( ); // or something...

  oDomDoc.setProperty( "SelectionLanguage", "XPath");  //  for IE
  var oElem = oDomDoc.selectSingleNode( "//some_element");
  var str =Sarissa.serialize( oElem);

  ...
}

Sarissa & XMLHttpRequest

function gettime( ) { return (new Date()).getTime(); }

...

if( !Sarissa.IS_ENABLED_XMLHTTP) { critical_error( ); return; }

// uniq is needed for IE, otherwise we get a cached copy
var r ="/do?uniq=" + gettime( ) + "&";

r +='foo=' +bar; // ...

var xmlhttp =new XMLHttpRequest();  // Sarissa makes this cross-browser

xmlhttp.onreadystatechange =function( )
{
  if (xmlhttp.readyState ==4)
  {
    if (xmlhttp.status ==200)
    {
      callback( xmlhttp.responseText);  // or something...
    }
    else
    {
      resolve_error( xmlhttp.status);  // or something...
    }
  }
}

xmlhttp.open( "GET", r, true);
xmlhttp.send( null);

Bit-fiddling in C

long bit_set( long S, int n)
{return(S|(1<<n));}

long bit_clear( long S, int n)
{return(S&~(1<<n));}

int bit_in( long S, int n)
{return((S&(1<<n))!=0);}