Showing posts with label Sarissa. Show all posts
Showing posts with label Sarissa. Show all posts

2006-10-06

Sarissa: XML parsing (take 2)

Use the .getText() method goddamnit! Bit of a glitch there earlier.. Parsing and then (re-)serializing does not make that much sense in retrospect. 8-]

var oDomDoc = Sarissa.getDomDocument( );
oDomDoc = ( new DOMParser()).parseFromString( responseText, "text/xml");
if( oDomDoc.parseError != 0)
  {
    alert( "Virhe. Palvelin lähetti epäkelvon vastauksen. (parse error)");
    critical( );
  }

oDomDoc.setProperty( "SelectionLanguage", "XPath");
var oElem = oDomDoc.selectSingleNode( "//@some_attribute");

var str =Sarissa.getText( oElem);

...

2006-05-24

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);