$keepdoc = $testdoc;
$wrongdoc = "<html>\n  <body>\n    <p>Text</p>\n    <p>More text" . "\n  </body>\n</html>";
$testdoc = new xmddoc(explode("\n", $wrongdoc));
showDoc('Xml doc with syntax error + error message', $wrongdoc . "\n\n" . $testdoc->error);
$xmlFile = 'imsmanifest_reload.xml';
$presXmlFileContents = @file_get_contents_n($xmlFile) or die('XML file  ' . htmlspecialchars($xmlFile) . ' is missing...');
showDoc('XML file to be parsed', $presXmlFileContents);
$testdoc = new xmddoc(explode("\n", $presXmlFileContents));
unset($presXmlFileContents);
if ($testdoc->error) {
    die($xmlFile . ':<br><br>' . $testdoc->error);
}
$testdoc->xmd_update_many('metadata/lom/general/title,metadata/lom/general/description', 'langstring/@lang', 'fr');
$testdoc->xmd_copy_foreign_child($keepdoc, $keepdoc->xmd_select_single_element('sometag[2]'));
showDoc('After parsing, and after changing 2* langstring/@lang to fr, ' . 'and after adding a foreign doc, reconstruction from memory');
showDoc('Element tagname of first metadata/lom/* element', $testdoc->name[$testdoc->xmd_select_single_element('metadata/lom/*')]);
showDoc('Element namespace URI of metadata/lom/*[2]', $testdoc->xmd_get_ns_uri($testdoc->xmd_select_single_element('metadata/lom/*[2]')));
showDoc('Number of metadata/lom/* elements', count($testdoc->xmd_select_elements('metadata/lom/*')));
showDoc('Number of resources/resource/file elements with @href', count($testdoc->xmd_select_elements_where_notempty('resources/resource/file', '@href')));
$elems = $testdoc->xmd_select_elements_where('resources/resource', 'file[1]/@href', 'three.html');
showDoc('Resource identifier where file[1]/@href is three.html', $testdoc->xmd_value('@identifier', $elems[0]));
$elems = $testdoc->xmd_select_elements_where('resources/resource', '@identifier', $testdoc->xmd_value('organizations/organization/item[2]/@identifierref'));
showDoc('Resource href for item[2]', $testdoc->xmd_value('@href', $elems[0]));
$stuff = '';
foreach (array('@identifier', 'metadata/schema', '*/*/*/*[1]/langstring', 'resources/resource[3]/@href', 'resources/resource[3]/file/@href', 'resources/resource[3]/@*', 'resources/resource[3]/-/@href', 'resources/resource[3]/+/@href', 'resources/resource[1]/-/@href', 'resources/../../../../../../../@identifier', '@*', 'resources/@*', 'organizations/organization/item[4]/title', 'organizations/organization/item[-2]/title', 'organizations/organization/item[4]/@*', 'organizations/organization/item[4]/@*item', 'organizations/organization/item[2]/+item/title', 'organizations/organization/item[2]/+/+/+/title', 'organizations/organization/item[2]/-item', 'organizations/organization/item[1]/-item', 'organizations/organization/item[1]/-', 'organizations/organization/item[1]/-/@.') as $path) {
    $stuff .= $path . ' => ' . $testdoc->xmd_value($path) . "\n";
}
showDoc('Values of: @identifier, metadata/schema, ... (see below)', $stuff);
function showHtml($path)
{
    global $testdoc;
            chdir('..');
        }
    }
}
// XML and DB STUFF ----------------------------------------------------------->
$is_allowed_to_edit = isset($_user['user_id']) && $is_courseMember && api_is_allowed_to_edit();
$mdStore = new mdstore($is_allowed_to_edit);
if (($mdt_rec = $mdStore->mds_get(EID)) === FALSE) {
    // no record, default XML
    $mdt = $mdObj->mdo_generate_default_xml_metadata();
} else {
    $mdt = $mdt_rec;
}
$xhtxmldoc = new xmddoc(explode("\n", $mdt));
!$xhtxmldoc->error or give_up($xhtxmldoc->error);
if (SID == $id_range_first && ($prv = $xhtxmldoc->xmd_select_single_element('previous')) != -1) {
    $xhtxmldoc->xmd_remove_element($prv);
}
if (SID == $id_range_last && ($nxt = $xhtxmldoc->xmd_select_single_element('next')) != -1) {
    $xhtxmldoc->xmd_remove_element($nxt);
}
$before_first = $id_range_first ? TRUE : FALSE;
$after_last = FALSE;
foreach ($xhtxmldoc->xmd_select_elements('child') as $chEl) {
    $chId = $xhtxmldoc->attributes[$chEl]['identifier'];
    // no get_att yet...
    if ($after_last || ($before_first = $before_first && $chId != $id_range_first)) {
        $xhtxmldoc->xmd_remove_element($chEl);
        continue;
    }
    if (($mdt_rec = $mdStore->mds_get(BID . '.' . $chId)) === FALSE) {
Beispiel #3
0
        } else {
            // do some preparations
            return FALSE;
        }
        // signals XHT to generate new text from template
    } else {
        // store the new text in the cache...
        // possibly modify the text to be output...
        return $newtext;
        // often the output is identical to the new text
    }
}
// GENERATE OUTPUT ------------------------------------------------------------>
foreach (explode("\n", $xhtDoc->htt_array['HTTP']) as $httpXtra) {
    if ($httpXtra) {
        header($httpXtra);
    }
}
echo "<html>\n<head>", $xhtDoc->xht_fill_template('HEAD'), "\n</head>\n\n<body>\n";
$xhtDoc->xht_dbgn = 0;
// for template debug info, set to e.g. 10000
echo $xhtDoc->xht_fill_template('MAIN'), '<br><br>Child nodes of "description":';
foreach ($testdoc->children[$testdoc->xmd_select_single_element('description')] as $child) {
    echo '<br>', strlen($child), ': ', htmlspecialchars($child);
}
echo "\n\n</body>\n</html>\n";
if ($xhtDoc->xht_dbgn) {
    echo $xhtDoc->xht_dbgo;
}
// Note: XML document and templates would normally be fetched from (different)
// external sources, such as a file or a DB record...