sorry so long to answer i just got back into the swing of things from christmas break
ok it works like this
ummm first you need the DOMadapter class from
http://www.phpclasses.org/browse/file/16454.html
this makes it so the DOM walking will work in either php 4 or 5 d-(^_^)-b
then you use this
<?php
/*
* William Harris
* Get Document Xml By Id
*
* Kinda Straightforward :)
// Copyright (c) 2007 William Harris (http://upscalews.com, http://williamharris.name)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// just Credit Me Please and perhaps link to our site I would like that :)
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* and if you could visit our site www.upscalews.com we are a company by the name
* of Upscale Webservices we make websites if you need one designed
*/
/*
* function that parses all the way through the xml of a document (or a variable with xml in it as in this case)
* and gets all of it
*/
function nodeContent($node)
{
$str = "";
if ($node->hasChildNodes())
{
foreach($node->childNodes as $child)
{
$str .= $child->ownerDocument->saveXML($child);
}
}
return $str;
}
// include Dom Adapter for back and forwards compatibility -- so beautiful :_(
//require_once($_SERVER['DOCUMENT_ROOT'] . "/myinc/DOMAdapter.inc.php");
require_once("DOMAdapter.inc.php");
// header to serve as xml for production or plain text for testing
//header("origContent-Type: text/plain");
header("origContent-Type: text/xml");
// -------------- Begin Input XMl Logic -----------------//
// create input document object
$inxml = new DOMAdapter();
// make reference to xml
$indoc = $inxml->createDocument();
// pick page to get from
//$wpage = $_SERVER['DOCUMENT_ROOT'] . '/hustle/' ."index.html" ;
//$wpage = '../dir/index.html';
//$wpage = '../dir/' . $_POST['page'] . '.html';
$wpage = $_POST['dir'] . $_POST['page'] . '.html';
//More Testing
//var_dump($_POST['page']);
//var_dump($_POST['elId']);
//var_dump($_POST['dir']);
//var_dump($_POST['newEl']);
// load xml
$indoc->validateOnParse = true;
//$indoc->load($wpage);
$indoc->loadHTMLFile($wpage);
//var_dump($wpage);
//chose the id you wish to get from the document
//$elId = "page";
$elId = $_POST['elId'];
$newEl = $_POST['newEl'];
$selectEl = $indoc->getElementById($elId);
// -------------- End Input XMl Logic -----------------//
// make a string with the div origContent because you can't add xml from one source to another... no idea why
//$origContent = '<div id="page">' . nodeContent($selectEl) . "</div>";
$origContent = '<div id="'. $elId .'">' . nodeContent($selectEl) . "</div>";
if ( $newEl != NULL ) {
$newContent = '<div id="'. $newEl .'">' . nodeContent($selectEl) . "</div>";
$outContent = $newContent;
} else {
$outContent = $origContent;
}
// kind of element you want just in case you need that
//$kind = "div";
//$origContent = '<'. $kind . ' id="'. $elId .'">' . nodeContent($selectEl) . '</'. $kind .'>';
// a debuging type of thing var_dump($origContent);
// -------------- OUtupt XMl Logic Begin -----------------//
// create output document object
$outxml = new DOMAdapter();
// make reference to xml and form it
$outdoc = $outxml->createDocument();
//$outdoc->documentElement->setAttribute("id", $elId);
// load in Xml
$outdoc->loadXML($outContent);
// "print" it
echo $outdoc->saveXML();
// -------------- Output XMl Logic End -----------------//
?>
its ok but i would like some feedback (im a php n00b so any help would be appreciated) and i don’t think the domAdapter works right on php4
the feed back i would like is because modx uses voodoo (read: modRewrite) to generate the pages in a site and all my humble function does is crawl a variable full of xml (or (x)html in this case) for a node of a certain id and return it.
So in order for it work with modx you must use [glow=red,2,300]http[/glow] to get the html, like this:
// it's a post
&dir=http://yoursite.com/wanteddirectory/&page=desiredpage&elId=desireddocumentid
// if you want your output to have a different id
&dir=http://yoursite.com/wanteddirectory/&page=desiredpage&elId=desireddocumentid&newEl=newdocumentid
instead of any kind of relative link you like
and also would like to make it a modx plugin or snippet (again im new so i don’t even know which one it would be)
i know for a fact that it works because i have been using it on my test server ( php5
http://uniformserver.com for anyone interest in a wamp sort of thing ) on my pc for weeks
thanks for you time

d-(^_^)-b