jQuery.parseXML = function( xml ) { return jQuery( parseXML(xml) ); }; jQuery.fn.decHTML = function() { return this.each(function(){ var me = jQuery(this); var html = me.html(); me.html(html.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>')); }); }; function parseXML( xml ) { if( window.ActiveXObject && window.GetObject ) { var dom = new ActiveXObject( 'Microsoft.XMLDOM' ); dom.loadXML( xml ); return dom; } if( window.DOMParser ) return new DOMParser().parseFromString( xml, 'text/xml' ); throw new Error( 'No XML parser available' ); } function getAtribute( xml, attribute ) { return xml.attr( attribute ); } function getNumChildren( xml, element ) { return xml.find( element ).children().length; } function getText( xml ) { return xml.text(); } function getTextByElement( xml, element ) { return xml.find( element ).text(); } function getYield( xml ){ var yield = getTextByElement( xml, 'yield' ); if ( yield.length > 0 ) document.write( '

Yield: ' + yield + '

' ); } function returnYield( xml ){ var yield = getTextByElement( xml, 'yield' ); if ( yield.length > 0 ) return '

Yield: ' + yield + '

'; else return ''; } function returnYieldDiv( xml ) { var yield = getTextByElement( xml, 'yield' ); if ( yield.length > 0 ) return '
Yield: ' + yield + '
'; else return ''; } function getList( xml, nodeName ){ xml.find( nodeName ).children().each( function(){ var title = $( this ).attr( 'title' ); if ( title.length > 0 ) document.write( '

' + title + "

" ); $( this ).children().each( function(){ document.write( '

•  ' + $(this).text() + "

" ); }); }); } function getTime( xml ){ var pTime = getTextByElement( xml, 'time' ); var tTime = getTextByElement( xml, 'totaltime' ) if ( pTime.length > 0 || tTime.length > 0) { document.write( '

' ); if ( pTime.length > 0 ) document.write( 'Prep Time: ' + pTime ); if ( tTime.length > 0 ) document.write( 'Total Time: ' + tTime ); document.write( '

' ); } } function returnTime( xml ){ var pTime = getTextByElement( xml, 'time' ); var tTime = getTextByElement( xml, 'totaltime' ); if ( pTime.length > 0 || tTime.length > 0) { var t = '

'; if ( pTime.length > 0 ) t += 'Prep Time: ' + pTime; if ( tTime.length > 0 ) t += 'Total Time: ' + tTime; t += '

'; return t; } else return ''; } function returnTimeDiv( xml ){ var pTime = getTextByElement( xml, 'time' ); var tTime = getTextByElement( xml, 'totaltime' ); if ( pTime.length > 0 || tTime.length > 0) { var t = '
'; if ( pTime.length > 0 ) t += 'Prep Time: ' + pTime; if ( tTime.length > 0 ) t += 'Total Time: ' + tTime; t += '
'; return t; } else return ''; } function getPairedWith( xml ) { var pairedWith = xml.find( 'with' ); if ( pairedWith.length > 0 ) { pairedWith.each( function(){ document.write( '
  • ' + getText( $( this ) ) + '
  • '); }); } else { $( 'div#rPairedWith' ).css( 'display','none' ); } } function getNotes( xml ) { var notes = xml.find( 'notes' ); if ( notes.length > 0 ) { if ( notes.text().trim() != '' ) document.write( notes.text() ); else $( 'div#rNotes' ).css( 'display','none' ); } else { $( 'div#rNotes' ).css( 'display','none' ); } } function fillSelect( selectId, type ) { var $xml = $.parseXML(xmlString); var select = $( '#' + selectId ); if ( type == 'd' ) { $xml.find( 'country' ).each( function() { // add Country $( document.createElement('option') ) .attr( 'value', getAtribute( $( this ), 'id' ) ) .append( '-- ' + (getAtribute( $( this ), 'name' )).toUpperCase() + ' --' ) .appendTo( select ); // add City $( this ).find( 'city' ).each( function() { $( document.createElement('option') ) .attr( 'value', getAtribute( $( this ), 'id' ) ) .append( getAtribute( $( this ), 'name' ) ) .appendTo( select ); }); }); } else { // add Hotel $xml.find( 'hotel' ).each( function() { $( document.createElement('option') ) .attr( 'value', getAtribute( $( this ), 'id' ) ) .append( getAtribute( $( this ), 'name' ) ) .appendTo( select ); }); } } /***************************************************** Creating XML String ******************************************************/ // XML writer with attributes and smart attribute quote escaping function elementCDate(name,content,attributes){ var att_str = '' if (attributes) { // tests false if this arg is missing! att_str = formatAttributes(attributes) } var xml if (!content){ xml='<' + name + att_str + '/>' } else { xml='<' + name + att_str + '><![CDATA[' + content + ']]></'+name+'>' } return xml } function element(name,content,attributes){ var att_str = '' if (attributes) { // tests false if this arg is missing! att_str = formatAttributes(attributes) } var xml if (!content){ xml='<' + name + att_str + '/>' } else { xml='<' + name + att_str + '>' + content + '</'+name+'>' } return xml } var APOS = "'"; QUOTE = '"' var ESCAPED_QUOTE = { } ESCAPED_QUOTE[QUOTE] = '"' ESCAPED_QUOTE[APOS] = ''' /* Format a dictionary of attributes into a string suitable for inserting into the start tag of an element. Be smart about escaping embedded quotes in the attribute values. */ function formatAttributes(attributes) { var att_value var apos_pos, quot_pos var use_quote, escape, quote_to_escape var att_str var re var result = '' for (var att in attributes) { att_value = attributes[att] // Find first quote marks if any apos_pos = att_value.indexOf(APOS) quot_pos = att_value.indexOf(QUOTE) // Determine which quote type to use around // the attribute value if (apos_pos == -1 && quot_pos == -1) { att_str = ' ' + att + "='" + att_value.replace( '&', '&amp;' ) + "'" result += att_str continue } // Prefer the single quote unless forced to use double if (quot_pos != -1 && quot_pos < apos_pos) { use_quote = APOS } else { use_quote = QUOTE } // Figure out which kind of quote to escape // Use nice dictionary instead of yucky if-else nests escape = ESCAPED_QUOTE[use_quote] // Escape only the right kind of quote re = new RegExp(use_quote,'g') att_str = ' ' + att + '=' + use_quote + att_value.replace(re, escape) + use_quote result += att_str } return result }