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)
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
[PHP] DOM TextArea (and dom chart please)
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. :-) -- 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, 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 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)
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)
On Tue, Feb 2, 2010 at 2:29 PM, Ryan S gen...@yahoo.com 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
[PHP] DOM append to the top
Yo! I have a working form that adds user input to an XML file, it adds the new item element to the bottom of the list of previously created item elements. I would now like the new elements to be added to the top of the list. So far i've tried using: insertBefore() but i'm still getting elements added to the bottom. The XML looks like: Clothes Item.../Item Item.../Item Item.../Item - new items are added here Clothes This is what my code looks like: $y = $dom - getElementsByTagName(item); $dom - documentElement - insertBefore($Xitem,$y); If trying to pass the top most item node to insertbefore() but without any luck. Any ideas ? Cheers Mongoose -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Dom PDF Problem
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.
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
[PHP] DOM Source of Selection
Hi I am working on a project wherein i have to extract information from a webpage and use it for processing. However that information becomes available only when i manually select a part of the webpage and view its source information (DOM source of selection ). Now i want this to be automated . Is there any way in PHP by which i can directly refer to that particular DOM and load its source , say directly into a variable . Thank You. -- N.Harihara Krishnan B.Tech (III year ) CSE NIT Trichy
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
[PHP] DOM - change a tag name ??
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? -- 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 - 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 ??
On Wed, Mar 11, 2009 at 11:52 AM, Michael A. Peters mpet...@mac.com 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 ??
Andrew Ballard wrote: On Wed, Mar 11, 2009 at 11:52 AM, Michael A. Peters mpet...@mac.com 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 3:06 PM, Michael A. Peters mpet...@mac.com wrote: Andrew Ballard wrote: On Wed, Mar 11, 2009 at 11:52 AM, Michael A. Peters mpet...@mac.com 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 3:06 PM, Michael A. Peters mpet...@mac.com wrote: Andrew Ballard wrote: On Wed, Mar 11, 2009 at 11:52 AM, Michael A. Peters mpet...@mac.com 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. script/script and scRIpT/scRIpT 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 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
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
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
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
[PHP] DOM recursion
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. 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. 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 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): ?php class array2xml extends DomDocument { private $xpath; private $root; public function __construct($arr, $root='root') { parent::__construct(); /*** set the encoding ***/ $this-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
[PHP] DOM - Question about \0
Hi, I have question about \0 character with DOM : ?php $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 'pre' . htmlentities($dom-saveXML()); /* Result : ?xml version=1.0 encoding=utf-8? root blob![CDATA[foo]]/blob /root */ ? What to do with the character \0 ? encode this character to obtain : ![CDATA[foo00;bar]] ? 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
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 : ?php $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 'pre' . htmlentities($dom-saveXML()); /* Result : ?xml version=1.0 encoding=utf-8? root blob![CDATA[foo]]/blob /root */ ? What to do with the character \0 ? encode this character to obtain : ![CDATA[foo00;bar]] ? 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 #00; 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?
Nathan Rixham wrote: but assuming the above file is: ?xml version=1.0 ? chapter xmlns:xi=http://www.w3.org/2001/XInclude; a / /chapter 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: ?xml version=1.0 ? chapter xmlns:xi=http://www.w3.org/2001/XInclude; a / /chapter 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 = '?xml version=1.0 ? chapter xmlns:xi=http://www.w3.org/2001/XInclude; a / /chapter'; $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: ?xml version=1.0 ? chapter xmlns:xi=http://www.w3.org/2001/XInclude; a / /chapter 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 = '?xml version=1.0 ? chapter xmlns:xi=http://www.w3.org/2001/XInclude; a / /chapter'; $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: ?xml version=1.0 ? chapter xmlns:xi=http://www.w3.org/2001/XInclude; a / /chapter 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 = '?xml version=1.0 ? chapter xmlns:xi=http://www.w3.org/2001/XInclude; a / /chapter'; $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: ?xml version=1.0 ? chapter xmlns:xi=http://www.w3.org/2001/XInclude; a / /chapter 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 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 = '?xml version=1.0 ? chapter xmlns:xi=http://www.w3.org/2001/XInclude; a / /chapter'; $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: ?xml version=1.0 ? chapter xmlns:xi=http://www.w3.org/2001/XInclude; a / /chapter 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
[PHP] DOM API Namespaces - help?
Help?? I need to get the namespaces from the root node of a DomDocument.. ?xml version=1.0 ? chapter xmlns:xi=http://www.w3.org/2001/XInclude; para xi:include href=book.xml /xi:include /para /chapter I know I can retrieve the namespaceUri from the xi:include node using lookupNamespaceURI and -prefix but I need to get it from where it's defined in chapter but assuming the above file is: ?xml version=1.0 ? chapter xmlns:xi=http://www.w3.org/2001/XInclude; a / /chapter how would one retrieve xmlns:xi=http://www.w3.org/2001/XInclude; Thanks in advance! Nathan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] manipulating XML via php DOM
I don't think it is valid to have an opening tag and a closing tag with nothing in between. So an initial or and a final /or, as you recall it, should become or/. Second, I'm not sure I understand what you want to accomplish. From the example document you added is this the result you expect: And PropertyIsEqualTo PropertyNamegenus/PropertyName Literalontophaugs332/Literal /PropertyIsEqualTo Or/ Or/ /And Regards Jonas On Tue, 2007-11-20 at 10:27 -0800, pere roca wrote: please, I need some help with php DOM, for me it's becoming a hell! After trying other methods (check message from 19th november, called php DOM question), I'm getting a little more success to manipulate XML. From the code you can see below you generate this xml. Now I just want to keep only the initial Or and the final /Or. How can I access and delete the other (the between tags)? I suppose there is no way to create an initial Or without the associated /Or. Thanks a lot, Pere This is the WRONG XML generated from code. ... And PropertyIsEqualTo PropertyNamegenus/PropertyName Literalontophaugs332/Literal /PropertyIsEqualTo Or PropertyIsEqualTo PropertyNamegenus/PropertyName Literalcopris/Literal /PropertyIsEqualTo /Or Or PropertyIsEqualTo PropertyNamegenus/PropertyName Literalcopris2/Literal /PropertyIsEqualTo /Or /And ?php $species=array('ontophaugs332','copris','copris2'); $dom = new DOMDocument; //XML we will insert the data to $dom - load('edit_iberia3.xml'); $count=count($species); foreach ($species as $sp=$value) { //we pass parameters of the array $where_to_insert= $dom-getElementsByTagName('And')-item(0); $child = $dom-createElement('Or'); $or=$where_to_insert-appendChild($child); $child = $dom-createElement('PropertyIsEqualTo'); $first=$or-appendChild($child); $child2 = $dom-createElement('PropertyName'); $first-appendChild($child2); $child3 = $dom-createElement('Literal'); $first-appendChild($child3); //inserting the array data $values = $dom-createTextNode($value); $values = $child3-appendChild($values); } echo $dom-save(nou_iberia); ? -- View this message in context: http://www.nabble.com/manipulating-XML-via-php-DOM-tf4845510.html#a13862945 Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] manipulating XML via php DOM
Jonas, that's what I want to get (and is valid). Thanks, ... And PropertyIsEqualTo PropertyNamegenus/PropertyName Literalontophaugs332/Literal /PropertyIsEqualTo Or PropertyIsEqualTo PropertyNamegenus/PropertyName Literalontophaugs332/Literal /PropertyIsEqualTo PropertyIsEqualTo PropertyNamegenus/PropertyName Literalontophaugs/Literal /PropertyIsEqualTo /Or /And ... 2007/11/21, Jonas Geiregat [EMAIL PROTECTED]: I don't think it is valid to have an opening tag and a closing tag with nothing in between. So an initial or and a final /or, as you recall it, should become or/. Second, I'm not sure I understand what you want to accomplish. From the example document you added is this the result you expect: And PropertyIsEqualTo PropertyNamegenus/PropertyName Literalontophaugs332/Literal /PropertyIsEqualTo Or/ Or/ /And Regards Jonas On Tue, 2007-11-20 at 10:27 -0800, pere roca wrote: please, I need some help with php DOM, for me it's becoming a hell! After trying other methods (check message from 19th november, called php DOM question), I'm getting a little more success to manipulate XML. From the code you can see below you generate this xml. Now I just want to keep only the initial Or and the final /Or. How can I access and delete the other (the between tags)? I suppose there is no way to create an initial Or without the associated /Or. Thanks a lot, Pere This is the WRONG XML generated from code. ... And PropertyIsEqualTo PropertyNamegenus/PropertyName Literalontophaugs332/Literal /PropertyIsEqualTo Or PropertyIsEqualTo PropertyNamegenus/PropertyName Literalcopris/Literal /PropertyIsEqualTo /Or Or PropertyIsEqualTo PropertyNamegenus/PropertyName Literalcopris2/Literal /PropertyIsEqualTo /Or /And ?php $species=array('ontophaugs332','copris','copris2'); $dom = new DOMDocument; //XML we will insert the data to $dom - load('edit_iberia3.xml'); $count=count($species); foreach ($species as $sp=$value) { //we pass parameters of the array $where_to_insert= $dom-getElementsByTagName('And')-item(0); $child = $dom-createElement('Or'); $or=$where_to_insert-appendChild($child); $child = $dom-createElement('PropertyIsEqualTo'); $first=$or-appendChild($child); $child2 = $dom-createElement('PropertyName'); $first-appendChild($child2); $child3 = $dom-createElement('Literal'); $first-appendChild($child3); //inserting the array data $values = $dom-createTextNode($value); $values = $child3-appendChild($values); } echo $dom-save(nou_iberia); ? -- View this message in context: http://www.nabble.com/manipulating-XML-via-php-DOM-tf4845510.html#a13862945 Sent from the PHP - General mailing list archive at Nabble.com.
[PHP] manipulating XML via php DOM
please, I need some help with php DOM, for me it's becoming a hell! After trying other methods (check message from 19th november, called php DOM question), I'm getting a little more success to manipulate XML. From the code you can see below you generate this xml. Now I just want to keep only the initial Or and the final /Or. How can I access and delete the other (the between tags)? I suppose there is no way to create an initial Or without the associated /Or. Thanks a lot, Pere This is the WRONG XML generated from code. ... And PropertyIsEqualTo PropertyNamegenus/PropertyName Literalontophaugs332/Literal /PropertyIsEqualTo Or PropertyIsEqualTo PropertyNamegenus/PropertyName Literalcopris/Literal /PropertyIsEqualTo /Or Or PropertyIsEqualTo PropertyNamegenus/PropertyName Literalcopris2/Literal /PropertyIsEqualTo /Or /And ?php $species=array('ontophaugs332','copris','copris2'); $dom = new DOMDocument; //XML we will insert the data to $dom - load('edit_iberia3.xml'); $count=count($species); foreach ($species as $sp=$value) { //we pass parameters of the array $where_to_insert= $dom-getElementsByTagName('And')-item(0); $child = $dom-createElement('Or'); $or=$where_to_insert-appendChild($child); $child = $dom-createElement('PropertyIsEqualTo'); $first=$or-appendChild($child); $child2 = $dom-createElement('PropertyName'); $first-appendChild($child2); $child3 = $dom-createElement('Literal'); $first-appendChild($child3); //inserting the array data $values = $dom-createTextNode($value); $values = $child3-appendChild($values); } echo $dom-save(nou_iberia); ? -- View this message in context: http://www.nabble.com/manipulating-XML-via-php-DOM-tf4845510.html#a13862945 Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] php DOM question
hi everybody, I'm starting with the php DOM tools with some success. I want the user to dynamically alter the values of an xml tag (Filter) and incrustate this tag in a predefined XML. This original XML is like this: ... Rule Filter PropertyIsEqualTo PropertyNameuserID/PropertyName Literalnom USUARI/Literal /PropertyIsEqualTo /Filter Other_things /Other_things /Rule After executing the code (showed below), the XML tag is inserted but INSIDE of Filter tag, and should go AFTER. This is the wrong XML: Filter PropertyIsEqualTo PropertyNameuserID/PropertyName Literalnom USUARI/Literal /PropertyIsEqualTo the new Filter in wrong position Filter PropertyIsEqualTo PropertyNamegenus/PropertyName LiteralXXX/Literal /PropertyIsEqualTo /Filter /Filter Thanks everybody, this is the code: ? $xmlstr =XML Filter xmlns:gml=http://www.opengis.net/gml; PropertyIsEqualTo PropertyNamegenus/PropertyName Literalvalor A PASSAR/Literal /PropertyIsEqualTo /Filter $sxe = simplexml_load_string($xmlstr); //Values we will pass to the new Filter to insert $species=array('ontophaugs332','copris'); $dom = new DOMDocument; //XML we will insert the data to $dom - load('edit_iberia3.xml'); //Where will be the data inserted $where_to_insert= $dom-getElementsByTagName('Filter')-item(0);//-item(0); //we pass parameters of the array foreach ($species as $sp=$value) { $sxe-PropertyIsEqualTo-Literal=$value; //This function takes the node NODE of class SimpleXML and makes it into a DOMElement node $node = dom_import_simplexml($sxe); //This function returns a copy of the node to import and associates it with the current document. $node = $dom-importNode($node, true); $before_insert-appendChild($node); } //we save the XML file echo $dom-save(simples2); ? -- View this message in context: http://www.nabble.com/php-DOM-question-tf4838570.html#a13842759 Sent from the PHP - General mailing list archive at Nabble.com. -- 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 input 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? grid cols=24 rows=16 border=1 tabMove=yes/grid 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 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 input 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
[PHP] DOM
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 input types, say something like a real grid, or maybe a modal child popup? -- @~@ Might, Courage, Vision, SINCERITY. / v \ Simplicity is Beauty! May the Force and Farce be with you! /( _ )\ (Xubuntu 7.04) Linux 2.6.22.1 ^ ^ 20:36:01 up 14 days 22:40 1 user load average: 0.00 0.00 0.00 news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk -- 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 input 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
[PHP] DOM support
Hey! I have been looking through the docs writing test code and am going a little bit mad trying to work this out. Does anyone know where I can find a definitive list of DOM XML functions that are supported in specific versions of PHP? I write my code in Zend and it has 5.2.0, so everything works as per the manual but when I try to run on our production environment (5.0.4) then things go very, very wrong. In particular there doesn't seem to be a DOMXPath object. Failing a list of methods/versions - does anyone know what I can use in lieu of a DOMXPath object? TIA, Mikey -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Dom appendChild strips trailing text from within a node
I am trying to modify a node name and it mostly works, except that appendChild seems to strip the text that FOLLOWS after a subnode. Leading text and subnodes appear to be retained perfectly, just not text trailing the subnode. I tried using cloneNode, but that discarded the children even when I sent true as an argument. $html='divdiv1 bbold1 iitalic1uunderline1/u/i bold2/b div2bbold3/b uunderline/u/div'; $dom = new DomDocument; $dom-loadHTML($html); $nodes = $dom-getElementsByTagName('b'); foreach ($nodes as $oldNode) { $newNode = $dom-createElement('strong'); foreach($oldNode-childNodes as $thisOldNode) { if ($thisOldNode-nodeName == '#text') { $newNode-nodeValue .= $thisOldNode-nodeValue; } else { // appendChild seems to cause the issue // $newNode-appendChild($thisOldNode); } } $oldNode-parentNode-replaceChild($newNode, $oldNode); } //for debugging: echo nl2br(htmlentities($html)) . 'hr /'; echo nl2br(htmlentities(str_replace(array('body', '/body', '/html'), '', strstr($dom-saveXML(), 'body'; /* Should return: divdiv1 strongbold1 iitalic1uunderline1/u/i bold2/strong div2bbold3/b uunderline/u/div Instead returns: divdiv1 strongbold1 iitalic1uunderline1/u/i/strong div2bbold3/b uunderline/u/div */
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
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
[PHP] DOM and XSLTProcessor
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 strongsomething/strong, when shown to the screen, it shows lt;stronggt; etc... Here is the general outline: ?php $doc=new DOMDocument(1.0); $root=$doc-createElement(root); $wantedCode=$doc-createTextNode(strongSomething/strong); $root-appendChild($wantedCode); $doc-appendChild($root); $proc=new XSLTProcessor; $proc-importStylesheet(DOMDocument::load(test.xslt)); echo $proc-transformToXML($doc); ? SomeSheet is something like: xsl:template match=/ xsl:value-of select=./ /xsl:template The expected output that I would like to get is: strongSomething/strong (This would just bold my text, not literally see the strong tags). The actual output is: lt;stronggt;Somethinglt;/stronggt; (This outputs the strong 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: ?php $doc=new DOMDocument(1.0); $root=$doc-createElement(root); //note the change right here $wantedCode=$doc-createCDATASection(strongSomething/strong); $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
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 strongsomething/strong, when shown to the screen, it shows lt;stronggt; etc... Here is the general outline: ?php $doc=new DOMDocument(1.0); $root=$doc-createElement(root); $wantedCode=$doc-createTextNode(strongSomething/strong); $root-appendChild($wantedCode); $doc-appendChild($root); $proc=new XSLTProcessor; $proc-importStylesheet(DOMDocument::load(test.xslt)); echo $proc-transformToXML($doc); ? SomeSheet is something like: xsl:template match=/ xsl:value-of select=./ /xsl:template The expected output that I would like to get is: strongSomething/strong (This would just bold my text, not literally see the strong tags). The actual output is: lt;stronggt;Somethinglt;/stronggt; (This outputs the strong 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: ?php $doc=new DOMDocument(1.0); $root=$doc-createElement(root); //note the change right here $wantedCode=$doc-createCDATASection(strongSomething/strong); $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 strongsomething/strong, when shown to the screen, it shows lt;stronggt; etc... Here is the general outline: ?php $doc=new DOMDocument(1.0); $root=$doc-createElement(root); $wantedCode=$doc-createTextNode(strongSomething/strong); $root-appendChild($wantedCode); $doc-appendChild($root); $proc=new XSLTProcessor; $proc-importStylesheet(DOMDocument::load(test.xslt)); echo $proc-transformToXML($doc); ? SomeSheet is something like: xsl:template match=/ xsl:value-of select=./ /xsl:template The expected output that I would like to get is: strongSomething/strong (This would just bold my text, not literally see the strong tags). The actual output is: lt;stronggt;Somethinglt;/stronggt; (This outputs the strong 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: ?php $doc=new DOMDocument(1.0); $root=$doc-createElement(root); //note the change right here $wantedCode=$doc-createCDATASection(strongSomething/strong); $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
If there are parts of an XML document where you do not want '' and '' changed in 'lt;' and 'gt;' during the transformation then you need to use the disable-output-escaping option, as in the following example. xsl:if test=/root/footer div class=footer xsl:value-of select=/root/footer disable-output-escaping=yes / /div /xsl:if 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 strongsomething/strong, when shown to the screen, it shows lt;stronggt; etc... Here is the general outline: ?php $doc=new DOMDocument(1.0); $root=$doc-createElement(root); $wantedCode=$doc-createTextNode(strongSomething/strong); $root-appendChild($wantedCode); $doc-appendChild($root); $proc=new XSLTProcessor; $proc-importStylesheet(DOMDocument::load(test.xslt)); echo $proc-transformToXML($doc); ? SomeSheet is something like: xsl:template match=/ xsl:value-of select=./ /xsl:template The expected output that I would like to get is: strongSomething/strong (This would just bold my text, not literally see the strong tags). The actual output is: lt;stronggt;Somethinglt;/stronggt; (This outputs the strong 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: ?php $doc=new DOMDocument(1.0); $root=$doc-createElement(root); //note the change right here $wantedCode=$doc-createCDATASection(strongSomething/strong); $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
[PHP] PHP DOM saveHTML outputs entities
Hi, I'm loading a utf-8 xml file into PHP5 DOM, and then use saveHTML() method. The result output always convert characters to html entities in any case. How can I avoid this? I want to output utf-8 html string with no html entities. -thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP DOM saveHTML outputs entities
On 3/21/07, Eli [EMAIL PROTECTED] wrote: Hi, I'm loading a utf-8 xml file into PHP5 DOM, and then use saveHTML() method. The result output always convert characters to html entities in any case. How can I avoid this? I want to output utf-8 html string with no html entities. -thanks! What about html_entity_decode? http://www.php.net/html_entity_decode Tijnema -- 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] 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: #1513;#1500;#1493;#1501; 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 ?xml version=1.0 encoding=UTF-8? header. Example: ?php $dom = new DOMDocument('1.0','utf-8'); $dom-loadXML(htmlbodyשלום/body/html); $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] 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: #1513;#1500;#1493;#1501; 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 ?xml version=1.0 encoding=UTF-8? header. Example: ?php $dom = new DOMDocument('1.0','utf-8'); $dom-loadXML(htmlbodyשלום/body/html); $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: ?php $dom = new DOMDocument('1.0','utf-8'); $dom-loadXML(htmlbodyשלום/body/html); $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
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: ?php $dom = new DOMDocument('1.0','utf-8'); $dom-loadXML(htmlbodyשלום/body/html); $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] PHP DOM saveHTML outputs entities
Hello Eli, Best regards, === At 2007-03-21, 15:13:29 you wrote: === Hi, I'm loading a utf-8 xml file into PHP5 DOM, and then use saveHTML() how save() method method. The result output always convert characters to html entities in any case. How can I avoid this? I want to output utf-8 html string with no html entities. -thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php = = = = = = = = = = = = = = = = = = = = Nicholas Yim [EMAIL PROTECTED] 2007-03-21 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP DOM saveHTML outputs entities
Hi Nicholas, Nicholas Yim wrote: how save() method The save() method, or actually saveXML() method dumps the DOM in XML format and not HTML format, and browsers do not know how to handle it correctly. -thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] DOM File Permissions
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): bDOMCharacterData-appendData example/b ?php $doc = new DomDocument; //Load the xml file into DOMDocument $doc-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 bDOMCharacterData-appendData example/b ? 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
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): bDOMCharacterData-appendData example/b ?php $doc = new DomDocument; //Load the xml file into DOMDocument $doc-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 bDOMCharacterData-appendData example/b ? 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
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: Picture 1.png 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): bDOMCharacterData-appendData example/b ?php $doc = new DomDocument; //Load the xml file into DOMDocument $doc-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 bDOMCharacterData-appendData example/b ? 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: a peter = a id=peter No. Let me try to be more clear.. Say you got the element elem key=peter , 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 elem key=peter , 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 = EOXML ?xml version=1.0? !DOCTYPE note [ !ATTLIST elem key ID #IMPLIED ] doc elem key=peterThis is Peter/elem elem key=samThis is Sam/elem elem key=mikeThis is Mike/elem /doc 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
[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
RE: [PHP] DOM Element default ID attribute
This was not clear for me, do you mean: a peter = a id=peter 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
Re: [PHP] DOM Element default ID attribute
Peter Lauri wrote: This was not clear for me, do you mean: a peter = a id=peter No. Let me try to be more clear.. Say you got the element elem key=peter , 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
[PHP] DOM Validation using PHP
Hi there! I´m building a form validator using PHP and JS. It´s working fine by now, but I want to make a little improvement. Here is how its working now: 1. The user fill the form. Every time he leaves the field, the JS code match the value against a regexp to validate. 2. When the user submits the form, the PHP script match all the values against the same regexp's. Now, i want to validate my fields to prevent XSS, allowing my html tags but only the attributes that I want. I thought something like: (the tags and the valid attributes). ?php $form_html_validation = array( p=array(), a=array(href,name,rel), ol=array(), ul=array(), li=array(), h2=array(), h3=array(), h4=array(), h5=array(), h6=array(), strong=array(), em=array() ); $valid_elements = .join(,array_keys($form_html_validation)).; $userInput = strip_tags($userInput,$valid_elements); //perform DOM Attribute Validation ? But I don´t know how to loop over every attribute for each tag in the DomTree. Someone has any ideas? Thank You -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] DOM: Problem with loadXML(), createProcessingInstruction()
Apparently, loadXML() overwrites the existing structure of the document when called. The problem is that when I try to add a PI (namely a stylesheet), it adds it to the end of the document thus making so that the XML is not transformed by the client. To get around this, I thought I could just import my XML string into a DOMNode, but I do not see any method for that class analogous to the loadXML(). I looked at the possiblity of adding children to the document at specific positions (such that I could add the PI as the first child) but I do not see a DOMDocument method that allows it. appendChild() merely adds the child to the end of the document. Has anyone found a workaround for this; a workaround the fact that loadXML() completely replaces the existing document structure? thnx, Chris -- 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 = 'rootchild_elementblah/child_element/root'; $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 div and /div and what's between them, right? Playing with strpos and a simple stack for nested DIVs should let you hack this in a crude parser: ?php //Untested code, off the top of my head: $divs = array(); $stack = array(); $offset = 0; $len = strlen($html); while($offset $len){ $divpos = strpos($html, 'div', $offset); $endpos = strpos($html, '/div', $offset); if ($divpos === false $endpos === false) break; if ($divpos !== false $divpos $endpos){ array_push($stack, array($offset, $divpos)); $offset = $divpos + 1; } else{ $start = array_pop($stack); $divs = array($start, array($offset, $endpos)); $offset = $endpos + 1; } } var_dump($divs); ? 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.
Try the properties innerHTML or outerHTML, the later will include the enclosing tag. Satyam - Original Message - From: Michael Williams [EMAIL PROTECTED] To: php-general@lists.php.net 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: div id=name table stuff /table /div . . .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: php-general@lists.php.net 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: div id=name table stuff /table /div . . .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.
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: php-general@lists.php.net 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: php-general@lists.php.net 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: div id=name table stuff /table /div . . .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.
[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.
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: 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 - 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 . br /; } $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 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 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
[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: div id=name table stuff /table /div . . .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!
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, 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 td-fields? Example: ... tr id = 'tr01' td1/tdtd2/tdtd3/tdtd4/td /tr tr id = 'tr02' td1/tdtd2/tdtd3/tdtd4/td /tr tr id = 'tr01' td1/tdtd2/tdtd3/tdtd4/td /tr tr id = 'tr02' td1/tdtd2/tdtd3/tdtd4/td /tr ... 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 [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 . br /; } $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
[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 td fields on an external html page, where I just know some ids of the rows. Example: ... tr id = 'tr01' td1/tdtd2/tdtd3/tdtd4/td /tr tr id = 'tr02' td1/tdtd2/tdtd3/tdtd4/td /tr tr id = 'tr01' td1/tdtd2/tdtd3/tdtd4/td /tr tr id = 'tr02' td1/tdtd2/tdtd3/tdtd4/td /tr ... 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
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: php-general@lists.php.net 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 td fields on an external html page, where I just know some ids of the rows. Example: ... tr id = 'tr01' td1/tdtd2/tdtd3/tdtd4/td /tr tr id = 'tr02' td1/tdtd2/tdtd3/tdtd4/td /tr tr id = 'tr01' td1/tdtd2/tdtd3/tdtd4/td /tr tr id = 'tr02' td1/tdtd2/tdtd3/tdtd4/td /tr ... 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 - 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 td fields on an external html page, where I just know some ids of the rows. Example: ... tr id = 'tr01' td1/tdtd2/tdtd3/tdtd4/td /tr tr id = 'tr02' td1/tdtd2/tdtd3/tdtd4/td /tr tr id = 'tr01' td1/tdtd2/tdtd3/tdtd4/td /tr tr id = 'tr02' td1/tdtd2/tdtd3/tdtd4/td /tr ... 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
[PHP] DOM XML : set_attribute()
Hi, I am working with PHP 4.3 on windows. I am using PHP DOM functions to update the XML file. When I try to set the attribute of a particular node, the subsequent get returns the set value, but it doesn't reflect in the memory structure. echo ###,$build_node-get_attribute('path'); = this returns the original path value. $build_node-set_attribute('path', 'new_path'); echo ###,$build_node-get_attribute('path'); = this returns the new_path value. var_dump($build_node); = This does not reflect the change in path attribute for the build_node, it shows the the original path value. Can anybody help me in this issue? Thanks, Jils
[PHP] DOM/XML Query
I'm having some problems using PHP5 on Windows 2000 Server, running IIS 5. When trying to access a document from a xmldoc() function the system responds with the following, *Fatal error*: Call to undefined function xmldoc() in *XML Document* on line *Number* ** How do I fix this problem? Is there a fix for this? Thanks for your help
[PHP] DOM saveHTML() not outputting XHTML Strict
Hi, I have a class which will build, and output, an HTML table. To create the internal elements more simply I'm using a DOMDocument, with a root element of 'table' then outputting with the -saveHTML() method. This has worked fine during development, but I've run into a problem. In this table I have a drop-down list (select with options). If I want to set an option to selected I do this: $oOption-setAttribute('selected','selected'); Which, unfortunately, outputs as `option selected` instead of `option selected=selected` I need my output HTML to conform to XHTML strict. Is there any way I can force it to output XHTML Strict compliant tags? I guess the theoretically ideal solution would be to have a complete XHTML Strict DOMDocument, with my table in the body, then just outputting the table portion. I haven't found a way to do that without some nasty substr()'s and whatnot. Is there anyway to specify that a DOMDocument is really a portion of an XHTML Strict page, and output that accordingly? Just for clarity's sake, outputting -saveXML() isn't a real attrictive solution because it *always* puts the ?xml ? tag at the front, which I definitely do not want. Thanks, Chris -- 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 `option selected` 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
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 `option selected` 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 ?xml ? 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 `option selected` 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 ?xml ? 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
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 ?xml and ? $html = str_replace(?xml, , $html); $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 `option selected` 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 ?xml ? 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
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 ?xml and ? $html = str_replace(?xml, , $html); $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 `option selected` 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 ?xml ? 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
[PHP] CDATA in PHP DOM
Any idea what's wrong with the following? ($this_item['description'] has some html text I would like to paste as a CDATA section) $item-appendChild($dom-createElement('description', $dom-createCDATASection($this_item['description']))); Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: CDATA in PHP DOM
Guy Brom wrote: Any idea what's wrong with the following? ($this_item['description'] has some html text I would like to paste as a CDATA section) $item-appendChild($dom-createElement('description', $dom-createCDATASection($this_item['description']))); createElement takes a string not a DOMNode. Append the CDATASection to the element. Rob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: CDATA in PHP DOM
worked!! Rob Richards [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Guy Brom wrote: Any idea what's wrong with the following? ($this_item['description'] has some html text I would like to paste as a CDATA section) $item-appendChild($dom-createElement('description', $dom-createCDATASection($this_item['description']))); createElement takes a string not a DOMNode. Append the CDATASection to the element. Rob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] DOM namespace prefix troubles
Howdy folks, I'm using PHP 5.0.5 with the DOM enabled and I'm trying to create an XML doc with PHP. The problem I'm having is attaching a namespace prefix to a tag. What I'm trying to create is something like the following: ?xml version=1.0 encoding=UTF-8 ? Notes xmlns:cac=urn:oasis:names:specification:ubl:schema:xsd: CommonAggregateComponents-1.0 cac:Note / /Notes I am unable to create the cac:Note / element with the cac: namespace prefix. Any suggestions would be appreciated!
[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: script type=text/javascript language=Javascript![CDATA[alert('ddd');]]/script but I need it like this (because otherwise the javascript don't work): script type=text/javascript language=Javascript //![CDATA[ alert('ddd'); //]] /script First, script was using some bogus method names. Secondly, you try to do anything like the following (which do work)? $html = !DOCTYPE html PUBLIC \-//W3C//DTD XHTML 1.0 Strict//EN\ \http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\;\n. \n. html xmlns=\http://www.w3.org/1999/xhtml\; xml:lang=\en\ lang=\en\\n. head\n . script type=\text/javascript\ language=\Javascript\ /\n . /head\n . bodyhello\n . /body\n . /html; $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
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: script type=text/javascript language=Javascript![CDATA[alert('ddd');]]/script but I need it like this (because otherwise the javascript don't work): script type=text/javascript language=Javascript //![CDATA[ alert('ddd'); //]] /script First, script was using some bogus method names. Secondly, you try to do anything like the following (which do work)? $html = !DOCTYPE html PUBLIC \-//W3C//DTD XHTML 1.0 Strict//EN\ \http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\;\n. \n. html xmlns=\http://www.w3.org/1999/xhtml\; xml:lang=\en\ lang=\en\\n. head\n . script type=\text/javascript\ language=\Javascript\ /\n . /head\n . bodyhello\n . /body\n . /html; $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] PHP DOM XHTML - let me set my own javascript from code
Hi, I have problem with PHP DOM extension. How can I add my own javascript to javascript tag? I tried it using this code $html = !DOCTYPE html PUBLIC \-//W3C//DTD XHTML 1.0 Strict//EN\ \http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\;\n . \n . html xmlns=\http://www.w3.org/1999/xhtml\; xml:lang=\en\ lang=\en\\n . head\n . script type=\text/javascript\ language=\Javascript\ /\n . /head\n . bodyhello\n . /body\n . /html; $dom = new DomDocument(); $dom-preserveWhiteSpace = true; $dom-loadXML($html); $params = $dom-getElementsByTagName('script'); foreach ($params as $param) { $dat = $dom-createTextSection(\n\nalert('ddd');\n\n); $param-appendChild($dat); } echo $dom-saveXML(); but it encloses it to CDATA section automatically like this: script type=text/javascript language=Javascript![CDATA[alert('ddd');]]/script but I need it like this (because otherwise the javascript don't work): script type=text/javascript language=Javascript //![CDATA[ alert('ddd'); //]] /script Thanks for any idea, Petr -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php