Re: [PHP] DOM TextArea (and dom chart please)
> I think what you are looking for is $input2->textContent in PHP. Hey Andrew (and everyone else was was kind enough to write back) ! Found the solution, this is what i am using (and it works!), and i hope it helps anyone else who finds themselves in the spot i found myself $inputs2 = $dom->getElementsByTagName('textarea'); // Find textareas foreach ($inputs2 as $input2) { if(!$input2->nodeValue || $input2->nodeValue=="") { $input2->nodeValue="it works!"; } } Cheers guys! /R -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM TextArea (and dom chart please)
Michael A. Peters wrote: $website_data = new tidy('dom_test.html',$tidy_config); Doh! Should be $website_data = new tidy('dom_test.html',$tidy_config,'utf8'); Otherwise it has the same problem with multibyte characters that loadHTML() has. But with the 'utf8' specified it works beautifully. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM TextArea (and dom chart please)
On Tue, Feb 2, 2010 at 2:29 PM, Ryan S wrote: > Hey! > i'm just starting with PHP's DOM-XML and need a little help please. > > > Basically, first i am trying to see if a input like a textbox has a 'VALUE=' > associated with it, if yes, i leave it be, if no, i add a default value. > > This *is working* as can be seen by the attached code below. > > But a bit confused as to how to do the same for a textarea as textarea's do > not have a 'VALUE=' attribute. > > Heres my code: > > > $website_data = file_get_contents('dom_test.html');//load the website data, > > $dom = new DomDocument; //make a new DOM container in PHP > $dom->loadHTML($website_data); //load all the fetched data into the DOM > container > [snip] > // * now we come to the textarea bit that is not working * > > $inputs2 = $dom->getElementsByTagName('textarea'); // Find textareas > > foreach ($inputs2 as $input2) { > if(!$input2->firstChild.nodeValue=="") { > $input2->firstChild.nodeValue=="it works!"; > } > } > > > > echo $dom->saveHTML(); > ?> > > +++ > > // I have even tried this instead of the above: > > foreach ($inputs2 as $input2) { > if(!$input2->getAttribute("defaultValue")=="") { > $input2->setAttribute("defaultValue","it works!"); > } > } > > but no joy. > > I'm betting its pretty simple but i dont have a "DOM chart" for php, the only > ones i have been able to find via google are for javascript like this one: > http://www.hscripts.com/tutorials/javascript/dom/textarea-events.php > > > and that chart does not help much. Does anyone have a PHP DOM chart or a > resource that i can use to get started using this? > > Thanks in advance! > Ryan > I think what you are looking for is $input2->textContent in PHP. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM TextArea (and dom chart please)
Ryan S wrote: $website_data = file_get_contents('dom_test.html');//load the website data, $dom = new DomDocument; //make a new DOM container in PHP $dom->loadHTML($website_data); //load all the fetched data into the DOM container I'm not sure what the answer to your issue is, but mind if I make a couple off topic recommondations? 1) Use loadXML() instead of loadHTML() The reason is that loadHTML() will mutilate multibyte utf8 characters, replacing them with entities. You can still use $dom->saveHTML() to present the data if html is your target output. 2) loadXML() is less forgiving of malformed content, but you can fix that by using tidy to import your data $website_data = new tidy('dom_test.html',$tidy_config); $website_data->cleanRepair(); $dom->loadXML($website_data); where $tidy_config is the tidy configuration array. Make sure you set $tidy_config['output-xhtml'] = true; so that the output of tidy is clean X(ht)ML for loadXML(). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM TextArea (and dom chart please)
>// I have even tried this instead of the above: > >foreach ($inputs2 as $input2) { >if(!$input2->getAttribute("defaultValue")=="") { >$input2->setAttribute("defaultValue","it works!"); >} >} > >but no joy. > >I'm betting its pretty simple but i dont have a "DOM chart" for php, the only >ones i have been able to find via google are for javascript like this one: >http://www.hscripts.com/tutorials/javascript/dom/textarea-events.php > > >and that chart does not help much. Does anyone have a PHP DOM chart or a >resource that i can use to get started using this? > > When I get stuck on things like this, I find print_r() invaluable as it can basically dump out the objects entire contents, so I can see what values it has set. Hey Ash, Thanks for replyng. Where exactly do i use the print_r? and on which variable? Because i have tried it in different places but still no luck..
Re: [PHP] DOM TextArea (and dom chart please)
On Tue, 2010-02-02 at 11:29 -0800, Ryan S wrote: > Hey! > i'm just starting with PHP's DOM-XML and need a little help please. > > > Basically, first i am trying to see if a input like a textbox has a 'VALUE=' > associated with it, if yes, i leave it be, if no, i add a default value. > > This *is working* as can be seen by the attached code below. > > But a bit confused as to how to do the same for a textarea as textarea's do > not have a 'VALUE=' attribute. > > Heres my code: > > > $website_data = file_get_contents('dom_test.html');//load the website data, > > $dom = new DomDocument; //make a new DOM container in PHP > $dom->loadHTML($website_data); //load all the fetched data into the DOM > container > > $inputs = $dom->getElementsByTagName('input'); // Find Sections > > foreach ($inputs as $input) { //*** this block has the guts of the > functionality *** > if(!$input->getAttribute("value") || > $input->getAttribute("value")=="") { > $input->setAttribute("value", "RRR"); > } > } > > > > // * now we come to the textarea bit that is not working * > > $inputs2 = $dom->getElementsByTagName('textarea'); // Find textareas > > foreach ($inputs2 as $input2) { > if(!$input2->firstChild.nodeValue=="") { > $input2->firstChild.nodeValue=="it works!"; > } > } > > > > echo $dom->saveHTML(); > ?> > > +++ > > // I have even tried this instead of the above: > > foreach ($inputs2 as $input2) { > if(!$input2->getAttribute("defaultValue")=="") { > $input2->setAttribute("defaultValue","it works!"); > } > } > > but no joy. > > I'm betting its pretty simple but i dont have a "DOM chart" for php, the only > ones i have been able to find via google are for javascript like this one: > http://www.hscripts.com/tutorials/javascript/dom/textarea-events.php > > > and that chart does not help much. Does anyone have a PHP DOM chart or a > resource that i can use to get started using this? > > Thanks in advance! > Ryan > > > > -- > - The faulty interface lies between the chair and the keyboard. > - Creativity is great, but plagiarism is faster! > - Smile, everyone loves a moron. :-) > > > > > When I get stuck on things like this, I find print_r() invaluable as it can basically dump out the objects entire contents, so I can see what values it has set. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Dom PDF Problem
On Thu, Jul 02, 2009 at 04:29:01PM +0530, Pravinc wrote: > Hey all, > > I am working with generating PDF using Dom PDF. > > My problem is when I generate a single PDF , Its working fine. > > But when I code it in a loop for generating more than one PDF it gives some > error. > >$DomObj = new DOMPDF(); > > $DomObj->load_html_file($pth); > > $DomObj->render(); > > $pdf = $DomObj->output(); > > file_put_contents($MainDir."/Order-".$rsOrder[$ro]['OrderNumber']."/packing_ > slip.pdf", $pdf); > > the above code is in a loop > > I come to know that ,there is problem with memory leak. > > Also I thought that it was because I had not destroy the previously created > Object. > > So I also tried destroying it using unset.. I don't know whether its > destroying or not. > > Error is something like > > "Fatal error: Uncaught exception 'DOMPDF_Exception' with message 'No > block-level parent found. Not good.' in > D:\foldername\project\control\dompdf\include\inline_positioner.cls.php:68 > Stack trace: #0 D:\foldername\ project > \control\dompdf\include\frame_decorator.cls.php(381): > Inline_Positioner->position() #1 D:\foldername\ project > \control\dompdf\include\inline_frame_reflower.cls.php(56): > Frame_Decorator->position(". > > Can anyone please give me some way to solve this. > I had an error something like this when using FPDF. It would hack up the second PDF. I didn't investigate it a lot, but my solution was to instantiate the class *once*, and loop on the *rest* of it. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM Source of Selection
http://www.jonasjohn.de/lab/htmlsql.htm ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM - change a tag name ??
Andrew Ballard wrote: On Wed, Mar 11, 2009 at 3:06 PM, Michael A. Peters wrote: Andrew Ballard wrote: On Wed, Mar 11, 2009 at 11:52 AM, Michael A. Peters wrote: If I'm manipulating a dom object, is there a way to change the tag name? I know you manipulate just about everything else in a node - but is the tagName really off limits? from the documentation for DOMElement - /* Properties */ readonly public bool $schemaTypeInfo ; readonly public string $tagName ; so if I really needed to change it, I'd have to create a virgin node with the new name, identical attributes and children, and replace the existing node with the new one? Is there any other way to alter the tagName without doing all that? If this is related to your earlier post about attributes, is XSLT not an option? I hate to sound like a broken record, but PHP has support for XSL transformations and it sounds like that is exactly what you are trying to do. Andrew No. XSLT is certainly one of the technologies I'm going to look into, but right now I'm building a filter that (hopefully) will fully implement the Mozilla developer Content Security Policy server side before the document gets sent to the browser - by removing what would violate the specified CSP before it is sent. My primary interest in changing tag names is to ensure all tags are lower case so I can then run the rest of the filter. They are all lower case if you use loadHTML() but I don't want my class to assume it has a properly created DOMDocument to start with, so I want to walk the DOM and change bad tags/attribute names before I apply the CSP filtering. How are you traversing the DOM if it is not already properly formed? Every time I've ever tried to load a DOMDocument with xml that wouldn't validate, it blew up and the DOMDocument was left empty. I usually find loadHTML() to be more forgiving. The problem isn't with xml that doesn't validate, the problem is that HTML is not case sensitive. and are both legal xml but are different tags to xml. In xhtml the first is a script element, the second has no meaning and is discarded by the browser. However when sending the document as html (necessary for IE users, for example) - html is not case sensitive, the second is valid script tag. So if the content security policy says no scripts are allowed on the page, I need to catch both the second and the first. I was actually doing it with regex by saving the document to a buffer first but to avoid altering content, I had to make sure I was operating inside tags etc. and then it dawned on me - it's structured data, use a tool designed to work with structured data. If the class was just for me it wouldn't matter, but if I put the class out in the wild - $doc->createElement("SCriPt"); is legal and even can be used to produce legal validating HTML 4.01 upon saveHTML() but it would dodge how my class locates and checks for script elements. There doesn't seem to be a case insensitive way to find tags/elements in the php xml tools, so before my class does the filtering it needs to first make sure the tags/attributes are all lower case. How the potential users (if there ever are any) of my class get their page into DOMDocument is up to them, not me. They can loadHTML() or create it from scratch or import it from some other xml format. If their source is an html file (or buffer), I will recommend they run it through tidy first - tidy does wonders - but it's still up to them, not me, so my class can't assume the tags are lower case. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM - change a tag name ??
On Wed, Mar 11, 2009 at 3:06 PM, Michael A. Peters wrote: > Andrew Ballard wrote: >> >> On Wed, Mar 11, 2009 at 11:52 AM, Michael A. Peters >> wrote: >>> >>> If I'm manipulating a dom object, is there a way to change the tag name? >>> I know you manipulate just about everything else in a node - but is the >>> tagName really off limits? >>> >>> from the documentation for DOMElement - >>> >>> /* Properties */ >>> readonly public bool $schemaTypeInfo ; >>> readonly public string $tagName ; >>> >>> so if I really needed to change it, I'd have to create a virgin node with >>> the new name, identical attributes and children, and replace the existing >>> node with the new one? >>> >>> Is there any other way to alter the tagName without doing all that? >>> >> >> If this is related to your earlier post about attributes, is XSLT not >> an option? I hate to sound like a broken record, but PHP has support >> for XSL transformations and it sounds like that is exactly what you >> are trying to do. >> >> Andrew >> > > No. > XSLT is certainly one of the technologies I'm going to look into, but right > now I'm building a filter that (hopefully) will fully implement the Mozilla > developer Content Security Policy server side before the document gets sent > to the browser - by removing what would violate the specified CSP before it > is sent. > > My primary interest in changing tag names is to ensure all tags are lower > case so I can then run the rest of the filter. They are all lower case if > you use loadHTML() but I don't want my class to assume it has a properly > created DOMDocument to start with, so I want to walk the DOM and change bad > tags/attribute names before I apply the CSP filtering. How are you traversing the DOM if it is not already properly formed? Every time I've ever tried to load a DOMDocument with xml that wouldn't validate, it blew up and the DOMDocument was left empty. I usually find loadHTML() to be more forgiving. > That might be something where XSLT is better but I believe I need to install > some libraries and recompile php before I can use XSLT as it appears my > current build doesn't support it (according to phpinfo()) so playing with > XSLT is for another day. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM - change a tag name ??
Andrew Ballard wrote: On Wed, Mar 11, 2009 at 11:52 AM, Michael A. Peters wrote: If I'm manipulating a dom object, is there a way to change the tag name? I know you manipulate just about everything else in a node - but is the tagName really off limits? from the documentation for DOMElement - /* Properties */ readonly public bool $schemaTypeInfo ; readonly public string $tagName ; so if I really needed to change it, I'd have to create a virgin node with the new name, identical attributes and children, and replace the existing node with the new one? Is there any other way to alter the tagName without doing all that? If this is related to your earlier post about attributes, is XSLT not an option? I hate to sound like a broken record, but PHP has support for XSL transformations and it sounds like that is exactly what you are trying to do. Andrew No. XSLT is certainly one of the technologies I'm going to look into, but right now I'm building a filter that (hopefully) will fully implement the Mozilla developer Content Security Policy server side before the document gets sent to the browser - by removing what would violate the specified CSP before it is sent. My primary interest in changing tag names is to ensure all tags are lower case so I can then run the rest of the filter. They are all lower case if you use loadHTML() but I don't want my class to assume it has a properly created DOMDocument to start with, so I want to walk the DOM and change bad tags/attribute names before I apply the CSP filtering. That might be something where XSLT is better but I believe I need to install some libraries and recompile php before I can use XSLT as it appears my current build doesn't support it (according to phpinfo()) so playing with XSLT is for another day. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM - change a tag name ??
On Wed, Mar 11, 2009 at 11:52 AM, Michael A. Peters wrote: > If I'm manipulating a dom object, is there a way to change the tag name? > I know you manipulate just about everything else in a node - but is the > tagName really off limits? > > from the documentation for DOMElement - > > /* Properties */ > readonly public bool $schemaTypeInfo ; > readonly public string $tagName ; > > so if I really needed to change it, I'd have to create a virgin node with > the new name, identical attributes and children, and replace the existing > node with the new one? > > Is there any other way to alter the tagName without doing all that? > If this is related to your earlier post about attributes, is XSLT not an option? I hate to sound like a broken record, but PHP has support for XSL transformations and it sounds like that is exactly what you are trying to do. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] DOM - change a tag name ??
Unfortunately, you are correct. This is the only way to do it at the moment. tagName/nodeName are readonly in the DOM and are set when created. I know this is possible in the .NET world and I am still beside myself as to which is the better way. -Original Message- From: Michael A. Peters [mailto:mpet...@mac.com] Sent: Wednesday, March 11, 2009 1:40 PM To: php-general@lists.php.net Subject: Re: [PHP] DOM - change a tag name ?? Michael A. Peters wrote: > If I'm manipulating a dom object, is there a way to change the tag name? > I know you manipulate just about everything else in a node - but is the > tagName really off limits? > > from the documentation for DOMElement - > > /* Properties */ > readonly public bool $schemaTypeInfo ; > readonly public string $tagName ; > > so if I really needed to change it, I'd have to create a virgin node > with the new name, identical attributes and children, and replace the > existing node with the new one? > > Is there any other way to alter the tagName without doing all that? > I've not actually tried this (IE may be errors) - I will in a little bit, but is something like this really the only way to change a tag name? function changeNodeElement($document,$node,$elementTag) { $newNode = $document->createElement($elementTag); // get all attributes from old node $attributes = $node->attributes; foreach ($attributes as $attribute) { $name = $attribute->name; $value = $attribute->value; $newNode->setAttribute($name,$value); } // get all children from old node $children = $node->childNodes(); foreach ($children as $child) { // clone node and add it to newNode $newChild = $child->cloneNode(true); $newNode->appendChild($newChild); } // replace the old node with the newNode $node->parent->replaceChild($newNode,$node); } It seems that changing the tag name should be a little easier. I don't expect s/oldtag/newtag/ but am I just missing something obvious? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php __ Information from ESET Smart Security, version of virus signature database 3927 (20090311) __ The message was checked by ESET Smart Security. http://www.eset.com __ Information from ESET Smart Security, version of virus signature database 3927 (20090311) __ The message was checked by ESET Smart Security. http://www.eset.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM - change a tag name ??
Michael A. Peters wrote: If I'm manipulating a dom object, is there a way to change the tag name? I know you manipulate just about everything else in a node - but is the tagName really off limits? from the documentation for DOMElement - /* Properties */ readonly public bool $schemaTypeInfo ; readonly public string $tagName ; so if I really needed to change it, I'd have to create a virgin node with the new name, identical attributes and children, and replace the existing node with the new one? Is there any other way to alter the tagName without doing all that? I've not actually tried this (IE may be errors) - I will in a little bit, but is something like this really the only way to change a tag name? function changeNodeElement($document,$node,$elementTag) { $newNode = $document->createElement($elementTag); // get all attributes from old node $attributes = $node->attributes; foreach ($attributes as $attribute) { $name = $attribute->name; $value = $attribute->value; $newNode->setAttribute($name,$value); } // get all children from old node $children = $node->childNodes(); foreach ($children as $child) { // clone node and add it to newNode $newChild = $child->cloneNode(true); $newNode->appendChild($newChild); } // replace the old node with the newNode $node->parent->replaceChild($newNode,$node); } It seems that changing the tag name should be a little easier. I don't expect s/oldtag/newtag/ but am I just missing something obvious? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM recursion
please keep replies on list ... I enjoy my beatings in public ... Joanne Lane schreef: > On Tue, 2009-03-10 at 01:05 +0100, Jochem Maas wrote: > >> yeah but those from php-women should know better :-) >> my eye keeps picking up php-women since I had a very nice chat >> with JRF (of phpwomen.org) at phpuk. > > Hi Jochem, > I am sorry I did not get back to you earlier, as my 'weekend' is Monday > and Tuesday. sorry for what? and what's a weekend? > Please do not let this reflect poorly on phpwomen as they have been a did you notice the smiley? > great help to me in starting PHP and your help led me to the final > solution to get my code working as I needed, and I thank you for that. > > In future I will refrain from asking on this list and stay with the > forums. why? this list beats any forum hands down :-) we have Pedantic Rob, the-guy-that-wrote-the-da-vinci-code, somone whose been programming since they were doing it with Rocks[tm] and a concentration of other high class php-wizards you won't find anywhere else outside of the internals group. ... oh and there's me. but you can't have everything. granted the humor's a little whack but you get used to it, before you know it 'your one of them'. > Thank you again for you guidance no problem. :-) > J > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM recursion
Nathan Rixham schreef: > Jochem Maas wrote: >> Jochem Maas schreef: >>> Joanne Lane schreef: I am trying to create a class that recursively iterates over an array an creates XML tree to reflect a multidimensional array. I am not really a PHP coder, but am trying my hand. >>> I've seen 'real coders' write stuff thats leagues worse. >>> This is what I have so far. http://pastie.org/private/w75vyq9ub09p0uawteyieq I have tried a few methods, but I keep failing. Currently, all elements are appended to the root node. >> >> .. yes my pleasure, glad I could help, not a problem. phffft. > > all too often the case man, I'm sure free-w...@lists.php.net points here yeah but those from php-women should know better :-) my eye keeps picking up php-women since I had a very nice chat with JRF (of phpwomen.org) at phpuk. oh well it was a nice little exercise in DOM, something I haven't fully mastered yet. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM recursion
Jochem Maas wrote: Jochem Maas schreef: Joanne Lane schreef: I am trying to create a class that recursively iterates over an array an creates XML tree to reflect a multidimensional array. I am not really a PHP coder, but am trying my hand. I've seen 'real coders' write stuff thats leagues worse. This is what I have so far. http://pastie.org/private/w75vyq9ub09p0uawteyieq I have tried a few methods, but I keep failing. Currently, all elements are appended to the root node. .. yes my pleasure, glad I could help, not a problem. phffft. all too often the case man, I'm sure free-w...@lists.php.net points here -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM recursion
Jochem Maas schreef: > Joanne Lane schreef: >> I am trying to create a class that recursively iterates over an array an >> creates XML tree to reflect a multidimensional array. >> I am not really a PHP coder, but am trying my hand. > > I've seen 'real coders' write stuff thats leagues worse. > >> This is what I have so far. >> http://pastie.org/private/w75vyq9ub09p0uawteyieq >> >> I have tried a few methods, but I keep failing. >> Currently, all elements are appended to the root node. > .. yes my pleasure, glad I could help, not a problem. phffft. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM recursion
Joanne Lane schreef: > I am trying to create a class that recursively iterates over an array an > creates XML tree to reflect a multidimensional array. > I am not really a PHP coder, but am trying my hand. I've seen 'real coders' write stuff thats leagues worse. > This is what I have so far. > http://pastie.org/private/w75vyq9ub09p0uawteyieq > > I have tried a few methods, but I keep failing. > Currently, all elements are appended to the root node. line 44 is the issue (kind of), you're always adding to the root node, regardless of 'level' the createNode func needs a little extra something, I played with it for a few minutes and come up with this .. probably not exactly what you need but it might offer a little inspiration (not I also changed the form of the input array a little): encoding = "ISO-8859-1"; /*** format the output ***/ $this->formatOutput = true; /*** create the root element ***/ $this->root = $this->appendChild($this->createElement( $root )); $this->xpath = new DomXPath($this); } /* * creates the XML representation of the array * * @accesspublic * @paramarrayThe array to convert */ public function createNode( $arr, $node = null) { if (is_null($node)) $node = $this->root; foreach($arr as $element => $value) { if (is_numeric($element)) { if (is_array($value)) self::createNode($value, $node); } else { $child = $this->createElement($element, (is_array($value) ? null : $value)); $node->appendChild($child); if (is_array($value)) self::createNode($value, $child); } } } /* * Return the generated XML as a string * * @accesspublic * @returnstring * */ public function __toString() { return $this->saveXML(); } /* * array2xml::query() - perform an XPath query on the XML representation of the array * @param str $query - query to perform * @return mixed */ public function query($query) { return $this->xpath->evaluate($query); } } $array = array('employees'=> array('employee' => array( array( 'name'=>'bill smith', 'address'=> array('number'=>1, 'street'=>'funny'), 'age'=>25), array( 'name'=>'tom jones', 'address'=> array('number'=>12, 'street'=>'bunny'), 'age'=>88), array( 'name'=>'dudley doright', 'address'=> array('number'=>88, 'street'=>'munny'), 'age'=>23), array( 'name'=>'nellie melba', 'address'=> array('number'=>83, 'street'=>'sunny'), 'age'=>83))) ); try { $xml = new array2xml('root'); $xml->createNode( $array ); echo $xml; } catch (Exception $e) { var_dump($e); } > > How can I fix this so that the XML tree, correctly reflects the array > tree. > > TIA > J > > - > http://www.phpwomen.org/ > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM - Question about \0
On Sun, Mar 16, 2008 at 1:50 AM, dav <[EMAIL PROTECTED]> wrote: > Hi, > > I have question about \0 character with DOM : > >$cdata = 'foo' . "\0" . 'bar'; > > $dom = new DOMDocument('1.0', 'utf-8'); > $dom->formatOutput = true; > > $container = $dom->createElement('root'); > $blob = $dom->createElement('blob'); > > $blob->appendChild($dom->createCDATASection($cdata)); > > $container->appendChild($blob); > $dom->appendChild($container); > > echo '' . htmlentities($dom->saveXML()); > > /* > Result : > > > > > > */ > ?> > > > What to do with the character \0 ? encode this character to obtain : > ? or skip the character with str_replace("\0", '', > $cdata) ? > > What is the best thing to do ? i like to conserve the \0 because is a blob > data > > Jabber is how to transmit binary ? > > > Sorry for by bad english. > > > Thank you. > > -- > Free pop3 email with a spam filter. > http://www.bluebottle.com/tag/5 > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Maybe the entity "�" works? -- -Casey -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM API Namespaces - help?
Cheers indeed Rob! That DOMXPath solution is exactly what I was looking for; Many, Many Thanks, Nathan Rob wrote: Hi Nathan, Nathan Rixham wrote: Cheers Rob, But this is the problem, I don't know what the namespace/prefix is! ie "xi" and the following doesn't work: $root->getAttributeNS('http://www.w3.org/2000/xmlns/', '*'); further xmlns is ?not? a prefix so this won't work either.. $root->lookupPrefix('http://www.w3.org/2000/xmlns/'); we need to assume that we don't know the document we're working on, thus we don't know: a] if it has any namespaces defined b] if any, what the namespaces are c] if any, what the prefixes are. And I still can't find any way of finding this out, it should be simple enough surely? still help!? There are a couple of ways to do this. Using only DOM, you can grab the namespaces via XPath: $root = $dom->documentElement; $xpath = new DOMXPath($dom); $nodes = $xpath->query('namespace::*'); foreach ($nodes AS $node) { print "x: ".$node->localName."\n"; } A simpler solution is to use simplexml: $sxe = simplexml_import_dom($root); var_dump($sxe->getDocNamespaces(true)); Rob Nathan Rob wrote: Hi Nathan, You need to retrieve the attribute based on the xmlns namespace. Nathan Rixham wrote: Thanks Jessen, I'm using the DOM API (domdocument) in PHP 5 - and yes pull xmlns:xi="http://www.w3.org/2001/XInclude"; from the chapter or indeed any namespaces defined in the root node and store them in a variable. If anybody could shed any light it'd be greatly appreciated. $xml = ' http://www.w3.org/2001/XInclude";> '; $dom = new DOMDocument(); $dom->loadXML($xml); $root = $dom->documentElement; $attr = $root->getAttributeNS('http://www.w3.org/2000/xmlns/', 'xi'); var_dump($attr); Rob Nathan Per Jessen wrote: Nathan Rixham wrote: but assuming the above file is: http://www.w3.org/2001/XInclude";> how would one retrieve xmlns:xi="http://www.w3.org/2001/XInclude"; When you say 'retrieve', what do you really mean? You need to get the namespace value into a PHP variable? I would probably look at the namespace-uri() function in XSLT, but I don't know if you're using XSLT? /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM API Namespaces - help?
Hi Nathan, Nathan Rixham wrote: Cheers Rob, But this is the problem, I don't know what the namespace/prefix is! ie "xi" and the following doesn't work: $root->getAttributeNS('http://www.w3.org/2000/xmlns/', '*'); further xmlns is ?not? a prefix so this won't work either.. $root->lookupPrefix('http://www.w3.org/2000/xmlns/'); we need to assume that we don't know the document we're working on, thus we don't know: a] if it has any namespaces defined b] if any, what the namespaces are c] if any, what the prefixes are. And I still can't find any way of finding this out, it should be simple enough surely? still help!? There are a couple of ways to do this. Using only DOM, you can grab the namespaces via XPath: $root = $dom->documentElement; $xpath = new DOMXPath($dom); $nodes = $xpath->query('namespace::*'); foreach ($nodes AS $node) { print "x: ".$node->localName."\n"; } A simpler solution is to use simplexml: $sxe = simplexml_import_dom($root); var_dump($sxe->getDocNamespaces(true)); Rob Nathan Rob wrote: Hi Nathan, You need to retrieve the attribute based on the xmlns namespace. Nathan Rixham wrote: Thanks Jessen, I'm using the DOM API (domdocument) in PHP 5 - and yes pull xmlns:xi="http://www.w3.org/2001/XInclude"; from the chapter or indeed any namespaces defined in the root node and store them in a variable. If anybody could shed any light it'd be greatly appreciated. $xml = ' http://www.w3.org/2001/XInclude";> '; $dom = new DOMDocument(); $dom->loadXML($xml); $root = $dom->documentElement; $attr = $root->getAttributeNS('http://www.w3.org/2000/xmlns/', 'xi'); var_dump($attr); Rob Nathan Per Jessen wrote: Nathan Rixham wrote: but assuming the above file is: http://www.w3.org/2001/XInclude";> how would one retrieve xmlns:xi="http://www.w3.org/2001/XInclude"; When you say 'retrieve', what do you really mean? You need to get the namespace value into a PHP variable? I would probably look at the namespace-uri() function in XSLT, but I don't know if you're using XSLT? /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM API Namespaces - help?
Cheers Rob, But this is the problem, I don't know what the namespace/prefix is! ie "xi" and the following doesn't work: $root->getAttributeNS('http://www.w3.org/2000/xmlns/', '*'); further xmlns is ?not? a prefix so this won't work either.. $root->lookupPrefix('http://www.w3.org/2000/xmlns/'); we need to assume that we don't know the document we're working on, thus we don't know: a] if it has any namespaces defined b] if any, what the namespaces are c] if any, what the prefixes are. And I still can't find any way of finding this out, it should be simple enough surely? still help!? Nathan Rob wrote: Hi Nathan, You need to retrieve the attribute based on the xmlns namespace. Nathan Rixham wrote: Thanks Jessen, I'm using the DOM API (domdocument) in PHP 5 - and yes pull xmlns:xi="http://www.w3.org/2001/XInclude"; from the chapter or indeed any namespaces defined in the root node and store them in a variable. If anybody could shed any light it'd be greatly appreciated. $xml = ' http://www.w3.org/2001/XInclude";> '; $dom = new DOMDocument(); $dom->loadXML($xml); $root = $dom->documentElement; $attr = $root->getAttributeNS('http://www.w3.org/2000/xmlns/', 'xi'); var_dump($attr); Rob Nathan Per Jessen wrote: Nathan Rixham wrote: but assuming the above file is: http://www.w3.org/2001/XInclude";> how would one retrieve xmlns:xi="http://www.w3.org/2001/XInclude"; When you say 'retrieve', what do you really mean? You need to get the namespace value into a PHP variable? I would probably look at the namespace-uri() function in XSLT, but I don't know if you're using XSLT? /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM API Namespaces - help?
Hi Nathan, You need to retrieve the attribute based on the xmlns namespace. Nathan Rixham wrote: Thanks Jessen, I'm using the DOM API (domdocument) in PHP 5 - and yes pull xmlns:xi="http://www.w3.org/2001/XInclude"; from the chapter or indeed any namespaces defined in the root node and store them in a variable. If anybody could shed any light it'd be greatly appreciated. $xml = ' http://www.w3.org/2001/XInclude";> '; $dom = new DOMDocument(); $dom->loadXML($xml); $root = $dom->documentElement; $attr = $root->getAttributeNS('http://www.w3.org/2000/xmlns/', 'xi'); var_dump($attr); Rob Nathan Per Jessen wrote: Nathan Rixham wrote: but assuming the above file is: http://www.w3.org/2001/XInclude";> how would one retrieve xmlns:xi="http://www.w3.org/2001/XInclude"; When you say 'retrieve', what do you really mean? You need to get the namespace value into a PHP variable? I would probably look at the namespace-uri() function in XSLT, but I don't know if you're using XSLT? /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM API Namespaces - help?
Thanks Jessen, I'm using the DOM API (domdocument) in PHP 5 - and yes pull xmlns:xi="http://www.w3.org/2001/XInclude"; from the chapter or indeed any namespaces defined in the root node and store them in a variable. If anybody could shed any light it'd be greatly appreciated. Nathan Per Jessen wrote: Nathan Rixham wrote: but assuming the above file is: http://www.w3.org/2001/XInclude";> how would one retrieve xmlns:xi="http://www.w3.org/2001/XInclude"; When you say 'retrieve', what do you really mean? You need to get the namespace value into a PHP variable? I would probably look at the namespace-uri() function in XSLT, but I don't know if you're using XSLT? /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM API Namespaces - help?
Nathan Rixham wrote: > but assuming the above file is: > > http://www.w3.org/2001/XInclude";> > > > > how would one retrieve xmlns:xi="http://www.w3.org/2001/XInclude"; When you say 'retrieve', what do you really mean? You need to get the namespace value into a PHP variable? I would probably look at the namespace-uri() function in XSLT, but I don't know if you're using XSLT? /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] DOM
[snip] Out of curiosity, is there any effort in creating a new DOM that's easier for application builders (something like Visual Foxpro)? Does Web 2.0 or maybe 3.0 offer some new types, say something like a real grid, or maybe a modal child popup? [/snip] [potential holy war bits] There is no such thing as Web 2.0 much less 3.0. Really. AJAX is a METHODOLOGY (a quite simple one at that) not a LANGUAGE. [/potential holy war bits] Having said that(and someone else explained DOM earlier) There have been several very robust and cross-browser (more and better browser support as well) JavaScript libraries put together lately and most of these support some sort of AJAX functionality. Some of these may offer what you are looking for. Let's examine your "real grid" question for a moment; A table is a real grid. Not necessarily an interactive grid, but a real grid none the less. Are you looking for something along the lines of a tag that would be like this? In this example I have enabled a 24 column x 16 row grid and hitting the tab key will move between cells. As far as know nothing exists like this in the W3 specs for HTML, DHTML, or XHTML now and is not likely to anytime soon as these are all derivatives of SGML which is a mark-up language, not a modal language. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM
On Thu, July 26, 2007 7:39 am, Man-wai Chang wrote: > Does Web 2.0 or maybe 3.0 offer some new types, say something > like a real grid, or maybe a modal child popup? No, that would be a useful feature, and browser-makers have much more important (read: inane) features to implement. :-) -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM
On Thursday 26 July 2007, Man-wai Chang wrote: > Out of curiosity, is there any effort in creating a new DOM that's > easier for application builders (something like Visual Foxpro)? > > Does Web 2.0 or maybe 3.0 offer some new types, say something > like a real grid, or maybe a modal child popup? You're confusing two different things. The DOM is a standard API developed by the W3C for addressing tree data structures, generally XML or a data structure that maps to XML. It is language-independent, which is why the Javascript DOM functions look and act really really closely to the PHP DOM functions. Do not expect the DOM API to change any time soon. XHTML is a particular XML DocType. One can manipulate it using the DOM API. That is very frequently done using Javascript, but in PHP 5 can be done in PHP as well with essentially the same API. The DOM functions can be a bit clunky, though, so various Javascript libraries exist that wrap them up into some easier syntax. My preference is for jQuery, but there are many others. Web 2.0 is a marketing term for a technical style and visual design movement. It was invented by Tim O'Reilly as a somewhat joke, and picked up by people with too much time and not enough brains to mean "Dot Boom 2.0". Web 3.0 is a fictional term that is used only to make fun of people who use the term Web 2.0 with a straight face. What you're actually asking for is new elements in the DocType that offer richer form elements. Do not expect that any time soon on a massive scale. HTML/XHTML is unlikely to get such a thing any time soon. There is the XForms standard from W3C, but I don't know of anything that actually uses it. Microsoft would say "just use .NET", but that just gets boiled down to some variant of Javascript that runs only in every bug-fix release of IE. Probably the only useful "richer forms" system right now with any mass-market adoption is XUL, which is the XML-based interface language used by Gecko, the Firefox engine. It runs in pretty much any version of Firefox, but is a very different animal from HTML. http://www.xulplanet.com/ -- Larry Garfield AIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] DOM and XSLTProcessor
Thanks everyone, I was able to get it to work by using CDATA and disable-output-escaping. I guess I was not doing one or the other when I was testing. Thanks for all the help it replace a really... _really_ nasty regex, decode, output. -Logan -Original Message- From: Richard Lynch [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 10, 2007 7:57 PM To: Buesching, Logan J Cc: Tijnema !; php-general@lists.php.net Subject: RE: [PHP] DOM and XSLTProcessor On Mon, April 9, 2007 3:50 am, Buesching, Logan J wrote: > This could offer a possible workaround. > > Let me first state that I cannot simply do: > > echo htmlspecialchars_decode($proc->transformToXML($doc)); > > If I were to do that, then it would assume that all of these encodings > need to be decoded; which definitely is not the case. I only want to > do > this for a few of the encodings, which I will know before the XSL > processing. I guess I can do some processing after it went through > the > XSL Processor to decode some of the encodings that I do not want, but > that just seems like it would add a lot of unnecessary overhead if it > can be avoided. Can you special decode the limited subset on output, rather than doing all of them on output, or hacking into the XML on input? As I understand it... The point is that the DATA can't have < and > in it, so if you want that data to come through, you're going to have to encode/decode somewhere along the line. PHP automatically encodes for you for this very reason. It's still up to you to interpret the data correctly at the output end. Though I am kinda surprised the CDATA solution didn't do it... -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] DOM and XSLTProcessor
On Mon, April 9, 2007 3:50 am, Buesching, Logan J wrote: > This could offer a possible workaround. > > Let me first state that I cannot simply do: > > echo htmlspecialchars_decode($proc->transformToXML($doc)); > > If I were to do that, then it would assume that all of these encodings > need to be decoded; which definitely is not the case. I only want to > do > this for a few of the encodings, which I will know before the XSL > processing. I guess I can do some processing after it went through > the > XSL Processor to decode some of the encodings that I do not want, but > that just seems like it would add a lot of unnecessary overhead if it > can be avoided. Can you special decode the limited subset on output, rather than doing all of them on output, or hacking into the XML on input? As I understand it... The point is that the DATA can't have < and > in it, so if you want that data to come through, you're going to have to encode/decode somewhere along the line. PHP automatically encodes for you for this very reason. It's still up to you to interpret the data correctly at the output end. Though I am kinda surprised the CDATA solution didn't do it... -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM and XSLTProcessor
If there are parts of an XML document where you do not want '<' and '>' changed in '<' and '>' during the transformation then you need to use the disable-output-escaping option, as in the following example. You also need to insert such text into the XML document using the createCDATASection() method otherwise the tags will be converted BEFORE the XSLT processor gets to look at it. -- Tony Marston http://www.tonymarston.net http://www.radicore.org ""Buesching, Logan J"" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] This could offer a possible workaround. Let me first state that I cannot simply do: echo htmlspecialchars_decode($proc->transformToXML($doc)); If I were to do that, then it would assume that all of these encodings need to be decoded; which definitely is not the case. I only want to do this for a few of the encodings, which I will know before the XSL processing. I guess I can do some processing after it went through the XSL Processor to decode some of the encodings that I do not want, but that just seems like it would add a lot of unnecessary overhead if it can be avoided. Thanks for the idea though. -Logan -Original Message- From: Tijnema ! [mailto:[EMAIL PROTECTED] Sent: Monday, April 09, 2007 4:40 AM To: Buesching, Logan J Cc: php-general@lists.php.net Subject: Re: [PHP] DOM and XSLTProcessor On 4/9/07, Buesching, Logan J <[EMAIL PROTECTED]> wrote: > Greetings, > > > > I apologize if this is a little long, but I am trying to put as much > information as I have done in this first post. I am running PHP 5 and > attempting to use DOM to create data to show on a webpage and using > XSLTProcessor with an XSLT sheet to output it into XHTML. Everything is > pretty fine an dandy until I wish to print raw text, such as xdebug and > var_dump. > > > > My knowledge of DOM and XSLTProcessor is about a 5/10, such that I know > most basics, but not the more advanced things. Whenever I try to add > data using createTextNode, it is always escaped, such that if I do > something, when shown to the screen, it shows > <strong> etc... > > > > Here is the general outline: > > > > > $doc=new DOMDocument("1.0"); > > $root=$doc->createElement("root"); > > $wantedCode=$doc->createTextNode("Something"); > > $root->appendChild($wantedCode); > > $doc->appendChild($root); > > $proc=new XSLTProcessor; > > $proc->importStylesheet(DOMDocument::load("test.xslt")); > > echo $proc->transformToXML($doc); > > ?> > > > > SomeSheet is something like: > > > > > > > > > > The expected output that I would like to get is: > > Something > > (This would just bold my text, not literally see the tags). > > > > The actual output is: > > <strong>Something</strong> > > (This outputs the tags to the end user, which is what I do not > want). > > > > I checked the manual at: > http://us3.php.net/manual/en/function.dom-domdocument-createtextnode.php > . A user comment suggested to use CDATA nodes, so I attempted to change > my code to the following: > > > > > $doc=new DOMDocument("1.0"); > > $root=$doc->createElement("root"); > > //note the change right here > > $wantedCode=$doc->createCDATASection("Something"); > > $root->appendChild($wantedCode); > > $doc->appendChild($root); > > $proc=new XSLTProcessor; > > $proc->importStylesheet(DOMDocument::load("test.xslt")); > > echo $proc->transformToXML($doc); > > > > ?> > > > > But this was of no success; it just had the same output. > > > > Is there anyone that is able to help me out here? > > > > Thanks, > > Logan Try using htmlspecialchars_decode before outputting your data: http://www.php.net/manual/en/function.htmlspecialchars-decode.php Tijnema > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] DOM and XSLTProcessor
This could offer a possible workaround. Let me first state that I cannot simply do: echo htmlspecialchars_decode($proc->transformToXML($doc)); If I were to do that, then it would assume that all of these encodings need to be decoded; which definitely is not the case. I only want to do this for a few of the encodings, which I will know before the XSL processing. I guess I can do some processing after it went through the XSL Processor to decode some of the encodings that I do not want, but that just seems like it would add a lot of unnecessary overhead if it can be avoided. Thanks for the idea though. -Logan -Original Message- From: Tijnema ! [mailto:[EMAIL PROTECTED] Sent: Monday, April 09, 2007 4:40 AM To: Buesching, Logan J Cc: php-general@lists.php.net Subject: Re: [PHP] DOM and XSLTProcessor On 4/9/07, Buesching, Logan J <[EMAIL PROTECTED]> wrote: > Greetings, > > > > I apologize if this is a little long, but I am trying to put as much > information as I have done in this first post. I am running PHP 5 and > attempting to use DOM to create data to show on a webpage and using > XSLTProcessor with an XSLT sheet to output it into XHTML. Everything is > pretty fine an dandy until I wish to print raw text, such as xdebug and > var_dump. > > > > My knowledge of DOM and XSLTProcessor is about a 5/10, such that I know > most basics, but not the more advanced things. Whenever I try to add > data using createTextNode, it is always escaped, such that if I do > something, when shown to the screen, it shows > <strong> etc... > > > > Here is the general outline: > > > > > $doc=new DOMDocument("1.0"); > > $root=$doc->createElement("root"); > > $wantedCode=$doc->createTextNode("Something"); > > $root->appendChild($wantedCode); > > $doc->appendChild($root); > > $proc=new XSLTProcessor; > > $proc->importStylesheet(DOMDocument::load("test.xslt")); > > echo $proc->transformToXML($doc); > > ?> > > > > SomeSheet is something like: > > > > > > > > > > The expected output that I would like to get is: > > Something > > (This would just bold my text, not literally see the tags). > > > > The actual output is: > > <strong>Something</strong> > > (This outputs the tags to the end user, which is what I do not > want). > > > > I checked the manual at: > http://us3.php.net/manual/en/function.dom-domdocument-createtextnode.php > . A user comment suggested to use CDATA nodes, so I attempted to change > my code to the following: > > > > > $doc=new DOMDocument("1.0"); > > $root=$doc->createElement("root"); > > //note the change right here > > $wantedCode=$doc->createCDATASection("Something"); > > $root->appendChild($wantedCode); > > $doc->appendChild($root); > > $proc=new XSLTProcessor; > > $proc->importStylesheet(DOMDocument::load("test.xslt")); > > echo $proc->transformToXML($doc); > > > > ?> > > > > But this was of no success; it just had the same output. > > > > Is there anyone that is able to help me out here? > > > > Thanks, > > Logan Try using htmlspecialchars_decode before outputting your data: http://www.php.net/manual/en/function.htmlspecialchars-decode.php Tijnema > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM and XSLTProcessor
On 4/9/07, Buesching, Logan J <[EMAIL PROTECTED]> wrote: Greetings, I apologize if this is a little long, but I am trying to put as much information as I have done in this first post. I am running PHP 5 and attempting to use DOM to create data to show on a webpage and using XSLTProcessor with an XSLT sheet to output it into XHTML. Everything is pretty fine an dandy until I wish to print raw text, such as xdebug and var_dump. My knowledge of DOM and XSLTProcessor is about a 5/10, such that I know most basics, but not the more advanced things. Whenever I try to add data using createTextNode, it is always escaped, such that if I do something, when shown to the screen, it shows etc... Here is the general outline: createElement("root"); $wantedCode=$doc->createTextNode("Something"); $root->appendChild($wantedCode); $doc->appendChild($root); $proc=new XSLTProcessor; $proc->importStylesheet(DOMDocument::load("test.xslt")); echo $proc->transformToXML($doc); ?> SomeSheet is something like: The expected output that I would like to get is: Something (This would just bold my text, not literally see the tags). The actual output is: Something (This outputs the tags to the end user, which is what I do not want). I checked the manual at: http://us3.php.net/manual/en/function.dom-domdocument-createtextnode.php . A user comment suggested to use CDATA nodes, so I attempted to change my code to the following: createElement("root"); //note the change right here $wantedCode=$doc->createCDATASection("Something"); $root->appendChild($wantedCode); $doc->appendChild($root); $proc=new XSLTProcessor; $proc->importStylesheet(DOMDocument::load("test.xslt")); echo $proc->transformToXML($doc); ?> But this was of no success; it just had the same output. Is there anyone that is able to help me out here? Thanks, Logan Try using htmlspecialchars_decode before outputting your data: http://www.php.net/manual/en/function.htmlspecialchars-decode.php Tijnema -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP DOM saveHTML outputs entities
Tijnema ! wrote: Did you set the UTF8 format in the html_entity_decode function? so your code would become: loadXML("שלום"); $output = $dom->saveHTML(); header("Content-Type: text/html; charset=UTF-8"); echo html_entity_decode($output,ENT_QUOTES,"UTF-8"); ?> Yes. This works... thanks! :-) But actually I wanted to avoid the saveHTML() method from converting to html entities in the first place, if possible at all. -thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP DOM saveHTML outputs entities
On 3/21/07, Eli <[EMAIL PROTECTED]> wrote: > What about html_entity_decode? > http://www.php.net/html_entity_decode No. It doesn't help in this case. DOMDocument->saveHTML() method converts any non-ascii characters into entities. For example, if the dom document has the text node value of: שלום It converts the string to entities: שלום Although the string is already in UTF-8. The DOMDocument is already initialized with version "1.0" and encoding "UTF-8", the php file is in UTF-8, the xml file is in UTF-8 and got header. Example: loadXML("שלום"); $output = $dom->saveHTML(); header("Content-Type: text/html; charset=UTF-8"); echo $output; ?> -thanks Did you set the UTF8 format in the html_entity_decode function? so your code would become: loadXML("שלום"); $output = $dom->saveHTML(); header("Content-Type: text/html; charset=UTF-8"); echo html_entity_decode($output,ENT_QUOTES,"UTF-8"); ?> I'm not really sure about it, but i'm not using UTF8. Also have a look at the comments under the html_entity_decode function, and at the functions/comments of utf8_encode/utf8_decode. Tijnema -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP DOM saveHTML outputs entities
What about html_entity_decode? http://www.php.net/html_entity_decode No. It doesn't help in this case. DOMDocument->saveHTML() method converts any non-ascii characters into entities. For example, if the dom document has the text node value of: שלום It converts the string to entities: שלום Although the string is already in UTF-8. The DOMDocument is already initialized with version "1.0" and encoding "UTF-8", the php file is in UTF-8, the xml file is in UTF-8 and got encoding="UTF-8"?> header. Example: loadXML("שלום"); $output = $dom->saveHTML(); header("Content-Type: text/html; charset=UTF-8"); echo $output; ?> -thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM File Permissions
I would bet it's the www, sorry about that. I've had to change the user/group name for mine so it will sync up with the linux file server permissions across NFS. On Mar 7, 2007, at 2:56 PM, CK wrote: Hi, Thanks, attempted to use appServer without luck, these are the choices: On Mar 7, 2007, at 2:25 PM, Edward Vermillion wrote: PHP needs read/write access to the files. More than likely PHP is running as Apache so the files would need to be owned by Apache* (or whatever PHP is running at), not System. *Or at least give the Apache group (or whatever PHP is running at) r/w access, that way you don't have to resort to world r/w. On Mar 7, 2007, at 1:55 PM, CK wrote: The following code returns a permisson error: Quote: Warning: DOMDocument::save(./save1.xml) [function.DOMDocument- save]: failed to open stream: Permission denied in /Users/ username/Sites/xmlphp/dom/appendData/appendData.php on line 17 DOMCharacterData->appendData example I attempted changing the owner of each file to System and read/ write for each file, with the same result, MAC OS 10.4.8, without success, what steps are needed to correct this? This source returned for the remote server(http://bushidodeep.com/ php/dom/appendData/appendData.php): DOMCharacterData->appendData example Load('./employee.xml'); //We retreive the attibute named id of the employee element $employee = $doc->getElementsByTagName('employee')->item(0); //Create a New element $newElement = $doc->createElement('surname'); //Create a text node $textNode = $doc->createTextNode("Text Node Created"); //Append the Text Node into the newly created node. $newElement -> appendChild($textNode); //Append the new element to the employee element $employee -> appendChild($newElement); //Save the DOMDocument into a file. $test = $doc->save("./save1.xml"); echo "DOMCharacterData->appendData example" ?> Return True, . PHP Version 5.1.4 MySQL Client API version 5.0.19 .. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM File Permissions
PHP needs read/write access to the files. More than likely PHP is running as Apache so the files would need to be owned by Apache* (or whatever PHP is running at), not System. *Or at least give the Apache group (or whatever PHP is running at) r/ w access, that way you don't have to resort to world r/w. On Mar 7, 2007, at 1:55 PM, CK wrote: The following code returns a permisson error: Quote: Warning: DOMDocument::save(./save1.xml) [function.DOMDocument- save]: failed to open stream: Permission denied in /Users/username/ Sites/xmlphp/dom/appendData/appendData.php on line 17 DOMCharacterData->appendData example I attempted changing the owner of each file to System and read/ write for each file, with the same result, MAC OS 10.4.8, without success, what steps are needed to correct this? This source returned for the remote server(http://bushidodeep.com/ php/dom/appendData/appendData.php): DOMCharacterData->appendData example Load('./employee.xml'); //We retreive the attibute named id of the employee element $employee = $doc->getElementsByTagName('employee')->item(0); //Create a New element $newElement = $doc->createElement('surname'); //Create a text node $textNode = $doc->createTextNode("Text Node Created"); //Append the Text Node into the newly created node. $newElement -> appendChild($textNode); //Append the new element to the employee element $employee -> appendChild($newElement); //Save the DOMDocument into a file. $test = $doc->save("./save1.xml"); echo "DOMCharacterData->appendData example" ?> Return True, . PHP Version 5.1.4 MySQL Client API version 5.0.19 .. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM Element default ID attribute
On Wed, February 21, 2007 11:44 pm, Eli wrote: > Peter Lauri wrote: >> This was not clear for me, do you mean: >> >> => >> > > No. > > Let me try to be more clear.. > Say you got the element , then I want the > DOMDocument > to automatically convert the 'key' attribute to an ID-Attribute, as > done > with DOMElement::setIdAttribute() function. The ID-Attribute is > indexed > and can be quickly gotten via DOMDocument::getElementById() function. > > I'm trying to avoid looping on all nodes overriding the importNode() > and > __construct() methods of DOMDocument. Are the keys guaranteed to be unique? If not, you can't do that, because the IDs have to be unique, no? I suspect you'll simply have to walk the whole thing and do it the hard way, if it's even a Good Idea... You might be better off taking a step back and asking the list how they solved whatever problem you're trying to solve with auto-generating the IDs, as there may be a Better Way... -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM Element default ID attribute
Eli wrote: Let me try to be more clear.. Say you got the element , then I want the DOMDocument to automatically convert the 'key' attribute to an ID-Attribute, as done with DOMElement::setIdAttribute() function. The ID-Attribute is indexed and can be quickly gotten via DOMDocument::getElementById() function. I'm trying to avoid looping on all nodes overriding the importNode() and __construct() methods of DOMDocument. Add a DTD to the document defining your attribute as an ID. $xml = << ]> This is Peter This is Sam This is Mike EOXML; $dom = new DOMDocument(); $dom->loadXML($xml); if ($elem = $dom->getElementByID("sam")) { print $elem->textContent; } else { print "Element not found"; } Rob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM Element default ID attribute
Peter Lauri wrote: This was not clear for me, do you mean: => No. Let me try to be more clear.. Say you got the element , then I want the DOMDocument to automatically convert the 'key' attribute to an ID-Attribute, as done with DOMElement::setIdAttribute() function. The ID-Attribute is indexed and can be quickly gotten via DOMDocument::getElementById() function. I'm trying to avoid looping on all nodes overriding the importNode() and __construct() methods of DOMDocument. -thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] DOM Element default ID attribute
This was not clear for me, do you mean: => Best regards, Peter Lauri www.dwsasia.com - company web site www.lauri.se - personal web site www.carbonfree.org.uk - become Carbon Free -Original Message- From: Eli [mailto:[EMAIL PROTECTED] Sent: Thursday, February 22, 2007 12:42 AM To: php-general@lists.php.net Subject: [PHP] DOM Element default ID attribute Hi, I want to declare a default ID attribute to all elements in the document. For example: If an element got the attribute 'id' then I want it automatically to become the ID attribute of the element. How can I do that? -thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] [Solved] Re: [PHP] DOM: Problem with loadXML(), createProcessingInstruction()
Has anyone found a workaround for this; a workaround the fact that loadXML() completely replaces the existing document structure? It's amazing what you find out after you've already made yourself look foolish. $xmlStr = 'blah'; $doc = new DOMDocument( '1.0', 'UTF-8' ); $docFragment = $doc->createDocumentFragment(); $docFragment->appendXML( $xmlStr ); // Why this isn't called also loadXML() // I have no idea. It would make sense // that it would be so as to maintain // consistency in names of methods // where it relates to functionality, // particularly when that functionality is // similar across classes. $doc->appendChild( $doc->createProcessingInstruction( 'blah', 'blah' ); $doc->appendChild( $docFragment ); echo $doc->saveXML(); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM Question. No pun intended.
Crude outside-the-box work-around... You are only looking for This should give you offsets to the beginning/end of each DIV tag. I'm sure I've got a one-off error or I'm not tracking quite the right numbers, or that I'm tracking extra numbers you don't need, but the idea is sound. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM Question. No pun intended.
[EMAIL PROTECTED] wrote: Rob, I wasn't aware that that would work. I mean I suppose it should, but basically this is what I'm doing: 1) Create a new DOMDocument 2) DOMDocument->loadHTML() 3) find the elements I want with getElementsByTag() then finding the one with the correct attributes . . .at this point, I need the equivalent of DOMDocument->saveHTML() so that it outputs the *exact* html content. Are you saying that saveXML() will do what I want it to do; tags and all? It is the best option, though in reality there may not be a way to do this exactly as you want due to HTML not having to be valid XML. By exact, unless the input is valid XHTML, loadHTML is going to cause the HTML to be fiexed to be proper XML, so using $doc->saveXML($node) you will get the serialized of the element as it was created when loading the HTML (this includes any "fixes" the parser may have made. Rob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM Question. No pun intended.
Rob, I wasn't aware that that would work. I mean I suppose it should, but basically this is what I'm doing: 1) Create a new DOMDocument 2) DOMDocument->loadHTML() 3) find the elements I want with getElementsByTag() then finding the one with the correct attributes . . .at this point, I need the equivalent of DOMDocument->saveHTML() so that it outputs the *exact* html content. Are you saying that saveXML() will do what I want it to do; tags and all? Regards, Mike Quoting Rob <[EMAIL PROTECTED]>: [EMAIL PROTECTED] wrote: Satyam, I don't see any "innerHTML" or "outerHTML" in relation to PHP DOM. I'm familiar with them from a Javascript standpoint, but no references when it comes to PHP DOM. Regards, Mike Now that you have the element, why not just call: $doc->saveXML($node); Rob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM Question. No pun intended.
[EMAIL PROTECTED] wrote: Satyam, I don't see any "innerHTML" or "outerHTML" in relation to PHP DOM. I'm familiar with them from a Javascript standpoint, but no references when it comes to PHP DOM. Regards, Mike Now that you have the element, why not just call: $doc->saveXML($node); Rob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM Question. No pun intended.
Sorry, I immediatly thought about the client side. No, I don't know there is any way on the server side with PHP. Satyam - Original Message - From: <[EMAIL PROTECTED]> To: "Satyam" <[EMAIL PROTECTED]> Cc: Sent: Thursday, September 14, 2006 4:16 PM Subject: Re: [PHP] DOM Question. No pun intended. Satyam, I don't see any "innerHTML" or "outerHTML" in relation to PHP DOM. I'm familiar with them from a Javascript standpoint, but no references when it comes to PHP DOM. Regards, Mike Quoting Satyam <[EMAIL PROTECTED]>: Try the properties innerHTML or outerHTML, the later will include the enclosing tag. Satyam - Original Message - From: "Michael Williams" <[EMAIL PROTECTED]> To: Sent: Thursday, September 14, 2006 2:12 AM Subject: [PHP] DOM Question. No pun intended. Hi All, I'm having HTML DOM troubles. Is there any way to output the *EXACT* code contained in a node (child nodes and all)? For instance, I perform a $doc->loadHTML($file) and all is well. I then search through the document for specific NODEs with getElementsByTagName(). However, when I go to output the data from that node (say a specific DIV) I simply get the text without formatting and the like. Basically, I want the retrieved NODE to echo exactly what is contained. If the div looks like the following: stuff . . .I want it to give me exactly that when I do a NODE->textContent or NODE->nodeValue. I don't want just the text, I want all tags contained, etc. It would be nice to have DOMNode->saveHTML() similar to the DOMDocument->saveHTML(). FYI, I'm using the technique to "screen scrape" portions of other pages from my site and compile items for a quick fix. Fortunately all my DIVs have IDs and I can loop through and find them by that attribute's value. I just can't output their EXACT data once I have them. :-\ Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM Question. No pun intended.
Satyam, I don't see any "innerHTML" or "outerHTML" in relation to PHP DOM. I'm familiar with them from a Javascript standpoint, but no references when it comes to PHP DOM. Regards, Mike Quoting Satyam <[EMAIL PROTECTED]>: Try the properties innerHTML or outerHTML, the later will include the enclosing tag. Satyam - Original Message - From: "Michael Williams" <[EMAIL PROTECTED]> To: Sent: Thursday, September 14, 2006 2:12 AM Subject: [PHP] DOM Question. No pun intended. Hi All, I'm having HTML DOM troubles. Is there any way to output the *EXACT* code contained in a node (child nodes and all)? For instance, I perform a $doc->loadHTML($file) and all is well. I then search through the document for specific NODEs with getElementsByTagName(). However, when I go to output the data from that node (say a specific DIV) I simply get the text without formatting and the like. Basically, I want the retrieved NODE to echo exactly what is contained. If the div looks like the following: stuff . . .I want it to give me exactly that when I do a NODE->textContent or NODE->nodeValue. I don't want just the text, I want all tags contained, etc. It would be nice to have DOMNode->saveHTML() similar to the DOMDocument->saveHTML(). FYI, I'm using the technique to "screen scrape" portions of other pages from my site and compile items for a quick fix. Fortunately all my DIVs have IDs and I can loop through and find them by that attribute's value. I just can't output their EXACT data once I have them. :-\ Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM Question. No pun intended.
Try the properties innerHTML or outerHTML, the later will include the enclosing tag. Satyam - Original Message - From: "Michael Williams" <[EMAIL PROTECTED]> To: Sent: Thursday, September 14, 2006 2:12 AM Subject: [PHP] DOM Question. No pun intended. Hi All, I'm having HTML DOM troubles. Is there any way to output the *EXACT* code contained in a node (child nodes and all)? For instance, I perform a $doc->loadHTML($file) and all is well. I then search through the document for specific NODEs with getElementsByTagName(). However, when I go to output the data from that node (say a specific DIV) I simply get the text without formatting and the like. Basically, I want the retrieved NODE to echo exactly what is contained. If the div looks like the following: stuff . . .I want it to give me exactly that when I do a NODE->textContent or NODE->nodeValue. I don't want just the text, I want all tags contained, etc. It would be nice to have DOMNode->saveHTML() similar to the DOMDocument->saveHTML(). FYI, I'm using the technique to "screen scrape" portions of other pages from my site and compile items for a quick fix. Fortunately all my DIVs have IDs and I can loop through and find them by that attribute's value. I just can't output their EXACT data once I have them. :-\ Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM - parse HTML document [solved]
At 10:02 PM +0200 9/13/06, Leonidas Safran wrote: Hello Tedd, Interesting -- it doesn't work for me. I keep getting -- Parse error: parse error, unexpected T_OBJECT_OPERATOR -- in your if statement. But, I don't see the problem. Maybe it has something to do with your php version. I have php 5.04 installed (Fedora Core 4 rpm package). Hope that helps! Regards, LS Yep, that was it -- I'm working with 4. tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM - parse HTML document [solved]
Hello Tedd, > Interesting -- it doesn't work for me. I keep getting -- > Parse error: parse error, unexpected T_OBJECT_OPERATOR > -- in your if statement. But, I don't see the problem. Maybe it has something to do with your php version. I have php 5.04 installed (Fedora Core 4 rpm package). Hope that helps! Regards, LS -- "Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ... Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM - parse HTML document [solved]
At 12:07 AM +0200 9/13/06, Leonidas Safran wrote: Hello all, I have found a way... $doc = new DomDocument(); $doc->loadHTMLFile($source["url"]); $elements = $doc->getElementsByTagName("tr"); $i = 0; while( $elements->item($i) ){ if( $elements->item($i)->hasAttributes() && preg_match("/td[0|1]/",$elements->item($i)->getAttribute("id")) > 0 ){ echo $elements->item($i)->nodeValue . ""; } $i++; } Works like i want... Regards, LS Interesting -- it doesn't work for me. I keep getting -- Parse error: parse error, unexpected T_OBJECT_OPERATOR -- in your if statement. But, I don't see the problem. tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM - parse HTML document [solved]
Hello all, I have found a way... $doc = new DomDocument(); $doc->loadHTMLFile($source["url"]); $elements = $doc->getElementsByTagName("tr"); $i = 0; while( $elements->item($i) ){ if( $elements->item($i)->hasAttributes() && preg_match("/td[0|1]/",$elements->item($i)->getAttribute("id")) > 0 ){ echo $elements->item($i)->nodeValue . ""; } $i++; } Works like i want... Regards, LS -- "Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ... Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM - parse HTML document
Hello Satyam, > That is correct but it is not complete. Everything that relies > on a unique id would fail, CSS amongst others(which is what this > article covers), but not the only one. > Basically there are two functions to get elements by id or name: > getElementById and getElementsByName. Notice the first one returns > a single element since there cannot be more than one, the second one > returns a collection of elements, since duplicates are allowed. Thus, > if you put an id in an element, it is because you want to reach it, > but if the id is duplicated then you cannot reach it any longer. Well, now that we know I can't change the fact that the website programmer used a multiple id (website is not maintained by me), how can I manage to grab the content of "my" -fields? Example: ... 1234 1234 1234 1234 ... Using DOM functions for sure :-) http://www.php.net/manual/en/ref.dom.php Thank you for any help! LS -- NEU: GMX DSL Sofort-Start-Set – blitzschnell ins Internet! Echte DSL-Flatrate ab 0,- Euro* http://www.gmx.net/de/go/dsl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM - parse HTML document
- Original Message - From: "Leonidas Safran" <[EMAIL PROTECTED]> By the way, because I found it strange to have more than one field with the same id, I looked on the famous selfhtml tutorial website http://de.selfhtml.org which says that unique id is only mandatory for css, but not for javascript actually. I was surprised... http://de.selfhtml.org/css/formate/zentrale.htm#individualformate http://en.selfhtml.org/css/formate/zentrale.htm#individualformate (english translation is a little different) That is correct but it is not complete. Everything that relies on a unique id would fail, CSS amongst others(which is what this article covers), but not the only one. Basically there are two functions to get elements by id or name: getElementById and getElementsByName. Notice the first one returns a single element since there cannot be more than one, the second one returns a collection of elements, since duplicates are allowed. Thus, if you put an id in an element, it is because you want to reach it, but if the id is duplicated then you cannot reach it any longer. Satyam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM - parse HTML document
Hello Satyam, Thanks for your answering... >> I don't really get it to work with that functions from >> http://www.php.net/manual/en/ref.dom.php >> I try to get the content of fields on an external html page, where >> I just know some ids of the rows. >> Example: >> ... >> >> 1234 >> >> >> 1234 >> >> >> 1234 >> >> >> 1234 >> >> ... >> PS: Please note, that id is written more than once. So >> DomDocument->getElementById('tr01') returns only one element and not two >> or more... >> I can't find out how to grab the data in the td fields... I don't find >> examples to look at... :-( >> I'd be really glad if somebody could give me some advice or tutorial >> websites about that... > To start with, an ID should never be repeated. A name can be repeated, > an ID shouldn't. That is why there is a function to get an array of > elements with a certain name but there is none to get a list of elements > with the same ID simply because there shouldn't be any. Something > helpful in traversing the DOM is any tool that gives you a good view of > the tree structure. One such comes already in the Firefox browser. Unfortunately, I have no way to modify the source html page, it's on the web. By the way, because I found it strange to have more than one field with the same id, I looked on the famous selfhtml tutorial website http://de.selfhtml.org which says that unique id is only mandatory for css, but not for javascript actually. I was surprised... http://de.selfhtml.org/css/formate/zentrale.htm#individualformate http://en.selfhtml.org/css/formate/zentrale.htm#individualformate (english translation is a little different) LS -- "Feel free" – 10 GB Mailbox, 100 FreeSMS/Monat ... Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM - parse HTML document
To start with, an ID should never be repeated. A name can be repeated, an ID shouldn't. That is why there is a function to get an array of elements with a certain name but there is none to get a list of elements with the same ID simply because there shouldn't be any. Something helpful in traversing the DOM is any tool that gives you a good view of the tree structure. One such comes already in the Firefox browser. Satyam - Original Message - From: "Leonidas Safran" <[EMAIL PROTECTED]> To: Sent: Monday, September 11, 2006 11:11 PM Subject: [PHP] DOM - parse HTML document Hello all, I don't really get it to work with that functions from http://www.php.net/manual/en/ref.dom.php I try to get the content of fields on an external html page, where I just know some ids of the rows. Example: ... 1234 1234 1234 1234 ... PS: Please note, that id is written more than once. So DomDocument->getElementById('tr01') returns only one element and not two or more... I can't find out how to grab the data in the td fields... I don't find examples to look at... :-( I'd be really glad if somebody could give me some advice or tutorial websites about that... Thanks a lot LS -- "Feel free" – 10 GB Mailbox, 100 FreeSMS/Monat ... Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM saveHTML() not outputting XHTML Strict
ACK! Of course I put errors in the code. But I just read if you want to strip out the first line that would be easy. Just use a regular expression and take it out. :) On 1/23/06 3:23 PM, "Jay Paulson" <[EMAIL PROTECTED]> wrote: > I don't know much about the ->saveXML() method but after reading the PHP > manual why can't you just do something like this: > > $xhtml = $dom->saveXML(); > > // strip out the > $html = str_replace(" $html = str_replace("?>", "", $html); > > Would that even work? > > > > > On 1/23/06 2:52 PM, "Chris" <[EMAIL PROTECTED]> wrote: > >> Steve Clay wrote: >> >>> Monday, January 23, 2006, 1:35:13 PM, Chris wrote: >>> >>> the ->saveHTML() method ... outputs as `` I need my output HTML to conform to XHTML strict. >>> >>> Since XHTML is XML, try ->saveXML()? >>> >>> Steve >>> >>> >> I've tried that, and it suits my purposes except for the fact that it >> always outputs the tag in the front, which I can't have. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM saveHTML() not outputting XHTML Strict
I don't know much about the ->saveXML() method but after reading the PHP manual why can't you just do something like this: $xhtml = $dom->saveXML(); // strip out the $html = str_replace("", "", $html); Would that even work? On 1/23/06 2:52 PM, "Chris" <[EMAIL PROTECTED]> wrote: > Steve Clay wrote: > >> Monday, January 23, 2006, 1:35:13 PM, Chris wrote: >> >> >>> the ->saveHTML() method ... outputs as `` >>> I need my output HTML to conform to XHTML strict. >>> >>> >> >> Since XHTML is XML, try ->saveXML()? >> >> Steve >> >> > I've tried that, and it suits my purposes except for the fact that it > always outputs the tag in the front, which I can't have. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM saveHTML() not outputting XHTML Strict
On 1/23/06, Chris <[EMAIL PROTECTED]> wrote: > Steve Clay wrote: > >Monday, January 23, 2006, 1:35:13 PM, Chris wrote: > > > >>the ->saveHTML() method ... outputs as `` > >>I need my output HTML to conform to XHTML strict. > >> > >Since XHTML is XML, try ->saveXML()? > > > >Steve > > > I've tried that, and it suits my purposes except for the fact that it > always outputs the tag in the front, which I can't have. Why? XHTML is technically XML which requires a xml declaration. In any case it is trivial to write a script that generates the files as XML and strips off the first line of the file. -Mike -- Michael E. Crute Software Developer SoftGroup Development Corporation Linux takes junk and turns it into something useful. Windows takes something useful and turns it into junk. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM saveHTML() not outputting XHTML Strict
Steve Clay wrote: Monday, January 23, 2006, 1:35:13 PM, Chris wrote: the ->saveHTML() method ... outputs as `` I need my output HTML to conform to XHTML strict. Since XHTML is XML, try ->saveXML()? Steve I've tried that, and it suits my purposes except for the fact that it always outputs the tag in the front, which I can't have. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM saveHTML() not outputting XHTML Strict
Monday, January 23, 2006, 1:35:13 PM, Chris wrote: > the ->saveHTML() method ... outputs as `` > I need my output HTML to conform to XHTML strict. Since XHTML is XML, try ->saveXML()? Steve -- http://mrclay.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP DOM XHTML - let me set my own javascript from code
Thanks a lot Rob, it's so simple! I don't know why I did't find it myself. Petr Rob wrote: Petr Smith wrote: but it encloses it to CDATA section automatically like this: language="Javascript"> but I need it like this (because otherwise the javascript don't work): // First, script was using some bogus method names. Secondly, you try to do anything like the following (which do work)? $html = "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\";>\n". "\n". "http://www.w3.org/1999/xhtml\"; xml:lang=\"en\" lang=\"en\">\n". "\n" . "\n" . "\n" . "hello\n" . "\n" . ""; $dom = new DomDocument(); $dom->preserveWhiteSpace = true; $dom->loadXML($html); $params = $dom->getElementsByTagName('script'); foreach ($params as $param) { $dat = $dom->createTextNode("\n//"); $param->appendChild($dat); $dat = $dom->createCDATASection("\n\nalert('ddd');\n\n//"); $param->appendChild($dat); $dat = $dom->createTextNode("\n"); $param->appendChild($dat); } echo $dom->saveXML(); Could also do it using through a comment node (following adds some linefeeds too): foreach ($params as $param) { $dat = $dom->createTextNode("\n"); $param->appendChild($dat); $dat = $dom->createComment("\n\nalert('ddd');\n\n"); $param->appendChild($dat); $dat = $dom->createTextNode("\n"); $param->appendChild($dat); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP DOM XHTML - let me set my own javascript from code
Petr Smith wrote: but it encloses it to CDATA section automatically like this: language="Javascript"> but I need it like this (because otherwise the javascript don't work): // First, script was using some bogus method names. Secondly, you try to do anything like the following (which do work)? $html = "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\";>\n". "\n". "http://www.w3.org/1999/xhtml\"; xml:lang=\"en\" lang=\"en\">\n". "\n" . "\n" . "\n" . "hello\n" . "\n" . ""; $dom = new DomDocument(); $dom->preserveWhiteSpace = true; $dom->loadXML($html); $params = $dom->getElementsByTagName('script'); foreach ($params as $param) { $dat = $dom->createTextNode("\n//"); $param->appendChild($dat); $dat = $dom->createCDATASection("\n\nalert('ddd');\n\n//"); $param->appendChild($dat); $dat = $dom->createTextNode("\n"); $param->appendChild($dat); } echo $dom->saveXML(); Could also do it using through a comment node (following adds some linefeeds too): foreach ($params as $param) { $dat = $dom->createTextNode("\n"); $param->appendChild($dat); $dat = $dom->createComment("\n\nalert('ddd');\n\n"); $param->appendChild($dat); $dat = $dom->createTextNode("\n"); $param->appendChild($dat); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM XML compatible PHP4 & PHP5
On Monday 12 September 2005 02:08 pm, Florent Monnier wrote: > Hi, > > Is there a way to make dom xml applications compatible PHP4 and PHP5? > > Thanks You can use the PHP_VERSION predefined constant or the function_exists(string) http://us2.php.net/manual/en/function.function-exists.php What I did was created a Document Object. right now it only works with PHP5 I might add PHP4 support to it later tho when I have more time using this approach unless anyone can think of a better idea. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM: copying from one document to another
> Is there any way I can copy an element from one DOM document to another > without having to dissect the original node/element and create a new > node/element from scratch using the new DOM document and append to it? Never mind. Apparently I can use clone_node(). When I tried that before I was presented with different issues. But I now have those other issues sorted. My apologies for being a little dense. :p thnx, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM: browse childnodes but not recursively
28 maj 2005 kl. 19.32 skrev Jared Williams: childNodes contains the textnodes too, in this case the whitespace between each of . So, to put it in short words; how do I do to browse the content of the element id="5" withuot doing it recursively? I want to receive a list when I call childNodes (or equivalent) that gives me the elements with id 51-56, and a length of 6. for($child = $elements->item(0)->firstChild; $child; $child = $child->nextSibling) if ($child->nodeType == XML_ELEMENT_NODE) echo $child->getAttribute('id'), "\n"; Thanks for the answer! It doesn't really work in my case, since I'm trying to create a recursive function according the following: 1. I perform a search using xPath and get a search result as a DOMNodeList. 2. This list I send to a function that takes it as input, and whats function is to create a multidimensional array. 3. Foreach item in the list I check if it has any children. 4. If so, I do the recursive call, with the list of children as input. So far so good, but when I come to the second loop, when the input is the list from the childNodes, everything stops working... Sincerely Victor
RE: [PHP] DOM: browse childnodes but not recursively
> -Original Message- > From: Victor Spång Arthursson [mailto:[EMAIL PROTECTED] > Sent: 27 May 2005 17:25 > To: php-general@lists.php.net > Subject: [PHP] DOM: browse childnodes but not recursively > > Ciao! > > I really hope someone can help me on this, since I have been > putting in to much time in it now, and I have to show off > some results ;) > > The problem is that I can't browse nodelists in only one > dimension, that is, whitout getting the sub-nodes of the nodes. > > My XML reads: > > > Still got the blues > Gary Moore > > > Maggie May > Rod Stewart > UK > Pickwick > 8.50 > 1990 > > > Virgin records > 10.20 > 1990 > > > I get this as a DOMNodeList in the variable $elements. I will > write some examples, to describe my problem. > > echo $elements->length; > // outputs 1 > > var_dump($elements); > // outputs object(DOMNodeList)#5 (0) { } > > var_dump($elements->item(0)); // contents of element with id="5" > // outputs object(DOMElement)#4 (0) { } > > Here I come to the problem. What I want is to get a list of > the 6 elements inside element id="5", but not with child-childs. > > echo $elements->item(0)->childNodes->length; > // Outputs 13! childNodes contains the textnodes too, in this case the whitespace between each of . > So, to put it in short words; how do I do to browse the > content of the element id="5" withuot doing it recursively? I > want to receive a list when I call childNodes (or equivalent) > that gives me the elements with id 51-56, and a length of 6. > for($child = $elements->item(0)->firstChild; $child; $child = $child->nextSibling) if ($child->nodeType == XML_ELEMENT_NODE) echo $child->getAttribute('id'), "\n"; Jared -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM or DOM XML ?
Ok, that answers my questions. Thanks a lot! Chris Yann Larrivée wrote: Hello If you don't wish to have XML support please use. --disable-simplexml --disable-libxml --disable-xml By Default, libxml is needed to compile PHP5. It tries to load DOM. DOMXML is history :) Hop this helps. Yann On January 9, 2005 13:35, Chris wrote: I'm currently compiling (at the ./configure step at the moment) 5.03 on Redhat 9 and ran into something that confused me. I got the error message included below. [EMAIL PROTECTED] ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-gd --with-mysql=/usr/local/mysql41 --with-mysqli=/usr/local/mysql41/bin/mysql_config . . . Configuring extensions checking whether to enable LIBXML support... yes checking libxml2 install dir... no configure: error: xml2-config not found. Please check your libxml2 installation. That, in itself, isn't too confusing, it's looking for something that's not there. Simple. I've been trying to figure out a few things though, and could use outside help: 1) Why is it trying to enable LIBXML support? 2) Which extension is it trying to load? DOM? DOM XML? Something else? Upon review I think I'd like to compile in DOM, but the manual ( http://www.php.net/dom ) doesn't mention anything about how to compile it in. Thanks, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM or DOM XML ?
Hello If you don't wish to have XML support please use. --disable-simplexml --disable-libxml --disable-xml By Default, libxml is needed to compile PHP5. It tries to load DOM. DOMXML is history :) Hop this helps. Yann On January 9, 2005 13:35, Chris wrote: > I'm currently compiling (at the ./configure step at the moment) 5.03 on > Redhat 9 and ran into something that confused me. I got the error > message included below. > > [EMAIL PROTECTED] ./configure --with-apxs2=/usr/local/apache2/bin/apxs > --with-gd --with-mysql=/usr/local/mysql41 > --with-mysqli=/usr/local/mysql41/bin/mysql_config > . . . > Configuring extensions > checking whether to enable LIBXML support... yes > checking libxml2 install dir... no > configure: error: xml2-config not found. Please check your libxml2 > installation. > > > That, in itself, isn't too confusing, it's looking for something that's > not there. Simple. I've been trying to figure out a few things though, > and could use outside help: > > 1) Why is it trying to enable LIBXML support? > 2) Which extension is it trying to load? DOM? DOM XML? Something else? > > Upon review I think I'd like to compile in DOM, but the manual ( > http://www.php.net/dom ) doesn't mention anything about how to compile > it in. > > Thanks, > Chris pgpSs9HB8ne5Q.pgp Description: signature
Re: [PHP] DOM XML/XSL questions
Christian Stocker wrote: Use $dom->createProcessingInstruction($target, $data) ; and then append this to the document. that could maybe work see http://ch.php.net/manual/en/function.dom-domdocument-createprocessinginstruction.php for more details. Thank you Christian, the following code worked fine. (From within the DOM object) $this->preserveWhiteSpace = false; $this->resolveExternals = true; $styleSheet = $this->createProcessingInstruction("xml-stylesheet", "type='text/xsl' href='../../../course.xsl'"); $this->appendChild($styleSheet); $this->createRoot(); $this->formatOutput = TRUE; And the formatting is not lost. you didn't provide any ;) The DOM Extension doesn't make any assumptions about the formatting of your XML document (or correctly said, it doesn't insert whitespace "automagically" ) but you can try to set the property formatOutput just before saveXML: $doc->formatOutput = true; Never tested, but should work I already had formatOutput = true; in the sample code. Of course when I am loading the DOM from a string, I am providing the formatting, which DOM is honouring but when I am creating the DOM completely from php, you are right, I am providing no formatting. In this case, the formatOutput works as I would have expected, (default??)formatted output when true, and not formatted when false. It would seem that if you provide some formatting, DOM expects you to provide it all. When I have finished this current assignment, I'll try to follow the calls through from PHP to libxml2, and see if I can find something more. Once again, thanks for your help... Dusty -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM XML/XSL questions
On Wed, 27 Oct 2004 13:52:13 +0100, Dusty Bin <[EMAIL PROTECTED]> wrote: > I have a requirement to create an XML file which looks approximately like: > > > > >Item Text >... > > > The file needs to be formatted. > > I built a dom using the Dom extension, creating a document, adding > nodes, and I got a nicely formatted XML file from $dom->saveXML(); > > The only problem I had, was that I could see no way to add the > stylesheet definition to the XML. I'm not sure that a DOM should know > anything about stylesheets, but an XML file probably should. > > I managed to bypass the problem, by loading the dom from a file, with > the style sheet and the root element included, and then proceeding to > build the dom by adding the extra nodes. This also worked fine, but now > the output from $dom->saveXML() is no longer formatted. > Here is some sample code: > > $txt =<< > > xmlns='http://www.example.com/xml' > xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' > xsi:schemaLocation='http://www.example.com/test/xml article.xsd'> > > EOT; > > $dom = new DOMDocument(); > $dom->preserveWhiteSpace = FALSE; > $dom->resolveExternals = TRUE; > $dom->loadXML($txt); > > $item = $dom->createElement("Item"); > $itemText = $dom->createTextNode("Item Text"); > $item->appendChild($itemText); > $dom->documentElement->appendChild($item); > > $dom->formatOutput = TRUE; > > echo $dom->saveXML(); > ?> > > My questions are: > 1) How should I add a stylesheet to this type of document? (I do not > need to process the stylesheet in php, it is for the guidance of the end > user of the document, who may use it or modify it), > and, Use $dom->createProcessingInstruction($target, $data) ; and then append this to the document. that could maybe work see http://ch.php.net/manual/en/function.dom-domdocument-createprocessinginstruction.php for more details. > 2) Is this a (dare I say bug in an experimental extension) that if I > load the dom, and perform operations on the dom, I lose formatting(A dom > that is just loaded, or just created by dom operations, is correctly > formatted, a dom with mixed processes is not). The extension is not experimental anymore ;) And the formatting is not lost. you didn't provide any ;) The DOM Extension doesn't make any assumptions about the formatting of your XML document (or correctly said, it doesn't insert whitespace "automagically" ) but you can try to set the property formatOutput just before saveXML: $doc->formatOutput = true; Never tested, but should work chregu > TIA for any advice... Dusty > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich phone +41 1 240 56 70 | mobile +41 76 561 88 60 | fax +41 1 240 56 71 http://www.bitflux.ch | [EMAIL PROTECTED] | gnupg-keyid 0x5CE1DECB -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM loadXML not loading doctype as expected in PHP5
On Tue, 31 Aug 2004 11:47:22 -0400, David Numan <[EMAIL PROTECTED]> wrote: > It worked! Thank you so much! no problem > I couldn't find documentation for this anywhere. I think I will add a > note on the DOM Function page in the php docs. The properties are unfortunately not documented yet :( And yes, please just add a User Note for the time being) chregu > > -dave > > > > On Tue, 2004-08-31 at 01:23, Christian Stocker wrote: > > On Tue, 31 Aug 2004 00:27:25 -0400, David Numan <[EMAIL PROTECTED]> wrote: > > > Hi > > > > > > I'm working on a project using PHP5 and I'm using the DOM extension > > > quite heavily. I need to be able to store various character entities > > > such as $nbsp; and é Note: this is for a custom XML document, not > > > standard (X)HTML. > > > > > > When I load my XML string into my domDocument I've been trying > > > variations of $doctype1 and $doctype2 below. Here is my code: > > > > > > $doctype1 = << > > > > > > "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent";> > > > %ISOlat1; > > > > > "http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent";> > > > %ISOsymbol; > > > > > "http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent";> > > > %ISOspecial; > > > ]> > > > EODT; > > > > > > $doctype2 = ' > > "http://gv.ca/dtd/character-entities.dtd";>'; > > > > > > $xml = ''.$doctype1. > > >' '; > > > $dom = new domDocument(); > > > $dom->loadXML($xml); > > > echo $dom->saveXML(); > > > > > > The above code works as-is and the is present in the huge output. > > > However, when I change it to use $doctype2 the is no longer there > > > and returns the warning "Entity 'nbsp' not defined in Entity, line 1". > > > Of course the $doctype2 string is the one I need. > > > > > > What am I doing wrong? Why isn't it loading the external entities? Is > > > there some other way of doing this that I somehow missed? I tested the > > > exact same xml code using "xmllint -format -loaddtd file.xml" and it > > > worked fine. > > > > try if it works with > > > > $dom->resolveExternals = true: > > > > before $dom->load() > > > > not tested, but I assume it has something to do with not loading > > external entities > > > > chregu > > > > > > Tested on Gentoo with PHP 5.0.0 and 5.0.1 with libxml 2.6.11. > > > > > > Any ideas would be appreciated. > > > Thanks, > > > -- > > > David Numan <[EMAIL PROTECTED]> > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > -- > David H. Numan, Software Architect > Guided Vision: Internet Application Construction > (905) 528-3095 http://guidedvision.com > > -- christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich phone +41 1 240 56 70 | mobile +41 76 561 88 60 | fax +41 1 240 56 71 http://www.bitflux.ch | [EMAIL PROTECTED] | gnupg-keyid 0x5CE1DECB -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM loadXML not loading doctype as expected in PHP5
It worked! Thank you so much! I couldn't find documentation for this anywhere. I think I will add a note on the DOM Function page in the php docs. -dave On Tue, 2004-08-31 at 01:23, Christian Stocker wrote: > On Tue, 31 Aug 2004 00:27:25 -0400, David Numan <[EMAIL PROTECTED]> wrote: > > Hi > > > > I'm working on a project using PHP5 and I'm using the DOM extension > > quite heavily. I need to be able to store various character entities > > such as $nbsp; and é Note: this is for a custom XML document, not > > standard (X)HTML. > > > > When I load my XML string into my domDocument I've been trying > > variations of $doctype1 and $doctype2 below. Here is my code: > > > > $doctype1 = << > > > "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent";> > > %ISOlat1; > > > "http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent";> > > %ISOsymbol; > > > "http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent";> > > %ISOspecial; > > ]> > > EODT; > > > > $doctype2 = ' > "http://gv.ca/dtd/character-entities.dtd";>'; > > > > $xml = ''.$doctype1. > >' '; > > $dom = new domDocument(); > > $dom->loadXML($xml); > > echo $dom->saveXML(); > > > > The above code works as-is and the is present in the huge output. > > However, when I change it to use $doctype2 the is no longer there > > and returns the warning "Entity 'nbsp' not defined in Entity, line 1". > > Of course the $doctype2 string is the one I need. > > > > What am I doing wrong? Why isn't it loading the external entities? Is > > there some other way of doing this that I somehow missed? I tested the > > exact same xml code using "xmllint -format -loaddtd file.xml" and it > > worked fine. > > try if it works with > > $dom->resolveExternals = true: > > before $dom->load() > > not tested, but I assume it has something to do with not loading > external entities > > chregu > > > > Tested on Gentoo with PHP 5.0.0 and 5.0.1 with libxml 2.6.11. > > > > Any ideas would be appreciated. > > Thanks, > > -- > > David Numan <[EMAIL PROTECTED]> > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- David H. Numan, Software Architect Guided Vision: Internet Application Construction (905) 528-3095 http://guidedvision.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM loadXML not loading doctype as expected in PHP5
On Tue, 31 Aug 2004 00:27:25 -0400, David Numan <[EMAIL PROTECTED]> wrote: > Hi > > I'm working on a project using PHP5 and I'm using the DOM extension > quite heavily. I need to be able to store various character entities > such as $nbsp; and é Note: this is for a custom XML document, not > standard (X)HTML. > > When I load my XML string into my domDocument I've been trying > variations of $doctype1 and $doctype2 below. Here is my code: > > $doctype1 = << "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent";> > %ISOlat1; > "http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent";> > %ISOsymbol; > "http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent";> > %ISOspecial; > ]> > EODT; > > $doctype2 = ' "http://gv.ca/dtd/character-entities.dtd";>'; > > $xml = ''.$doctype1. >' '; > $dom = new domDocument(); > $dom->loadXML($xml); > echo $dom->saveXML(); > > The above code works as-is and the is present in the huge output. > However, when I change it to use $doctype2 the is no longer there > and returns the warning "Entity 'nbsp' not defined in Entity, line 1". > Of course the $doctype2 string is the one I need. > > What am I doing wrong? Why isn't it loading the external entities? Is > there some other way of doing this that I somehow missed? I tested the > exact same xml code using "xmllint -format -loaddtd file.xml" and it > worked fine. try if it works with $dom->resolveExternals = true: before $dom->load() not tested, but I assume it has something to do with not loading external entities chregu > > Tested on Gentoo with PHP 5.0.0 and 5.0.1 with libxml 2.6.11. > > Any ideas would be appreciated. > Thanks, > -- > David Numan <[EMAIL PROTECTED]> > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich phone +41 1 240 56 70 | mobile +41 76 561 88 60 | fax +41 1 240 56 71 http://www.bitflux.ch | [EMAIL PROTECTED] | gnupg-keyid 0x5CE1DECB -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM XML difference between PHP versions 4.2.1 and 4.3.3
Hi, Friday, October 24, 2003, 9:37:07 PM, you wrote: S> Hello S> I wonder if anyone can help me with this problem or suggest an alternative S> strategy. S> I have two PHP boxes, one windows box running PHP version 4.2.1 and DOM XML S> version 2.4.9, and the other one a FreeBSD box running PHP version 4.3.3 and S> DOM XML version 2.5.11. S> What I need to do is to join two XML documents together. The code below S> runs fine on the 4.2.1 box but fails on the 4.3.3 box. S> //$pagenodes_doc_xml and $menu_xml have been previously populated with S> valid XML document objects S> // get page nodes root element S> $pagenodes_xml = $pagenodes_doc_xml->document_element(); S> //locate portalroot in menu xml S> $ctx = xpath_new_context($menu_xml); S> $nodes = xpath_eval($ctx, "//[EMAIL PROTECTED]'portalroot']"); S> $portalroot = $nodes->nodeset[0]; S> //append pages nodes at portalroot location S> $new_xml = $portalroot->append_child($pagenodes_xml); S> The error is "Warning: append_child(): Can't append node, which is in a S> different document than the parent node". S> Simon I think you have to use clone node $pagenodes_xml = $pagenodes_doc_xml->document_element(); $newnode = $pagenodes_xml->clone_node(1); //don't remember why the 1 :) $ctx = xpath_new_context($menu_xml); $nodes = xpath_eval($ctx, "//[EMAIL PROTECTED]'portalroot']"); $portalroot = $nodes->nodeset[0]; $new_xml = $portalroot->append_child($newnode); -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP DOM XML Function
Hello, As far as I know from Christian Stocker (the domxml maintainer) - they are already pretty stable. They are tagged as "experimental" to avoid people complaints about API changes (API changes are necessary because DOMXML should have a DOM api, and it was pretty not like this at the beggining). However, we are using Krysalis with DOMXML (we have even renounced at Sablotron and we are using only domxml) for dynamic XML/XSL publishing, and the API is pretty stable already (there might be some leaks on windows, but we don't have any real data yet on this). Alexandru -- Alexandru COSTIN Chief Operating Officer http://www.interakt.ro/ +4021 411 2610 "Fgôk ÞôündÉö" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > do you have any idea about PHP DOM XML functions? > when will PHP DOM XML functions be stable? > > > Fatih Üstündað > Yöre Elektronik Yayýmcýlýk A.Þ. > 0 212 234 00 90 > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php