Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    New Coder
    Join Date
    Jun 2008
    Posts
    76
    Thanks
    6
    Thanked 6 Times in 6 Posts

    DOM XML stop escaping

    Hi there i am trying to use DOM to put data into an xml tree and pass that off to xsl what i was wondering is how do you pass XML to dom and not have it escaped for example

    PHP Code:
    $Template->paragraph("
                <strong>
                    Welcome to Site, an Australian based game server provider.
                </strong>"
    ); 
    Code:
    &lt;strong&gt;
    	Welcome to Site, an Australian based game server provider.
    &lt;/strong&gt;
    What i would like is

    Code:
    <strong>
    	Welcome to Site, an Australian based game server provider.
    </strong>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    That will need to be cdata wrapped. If you embed a tag within an xml document it treats it as a new element, which is not what you want. The other option is to leave it as is and convert it back using htmlspecialchars_decode.
    To change it, you'll need to alter the $Template object's method: paragraph.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    New Coder
    Join Date
    Jun 2008
    Posts
    76
    Thanks
    6
    Thanked 6 Times in 6 Posts
    i am using xsl to display the final result so i am not sure how well htmlspecialchars_decode will preform under heavy load

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Then wrap it in a cdata block. I think dom xml has it (dom xml is a little on the old side), but if it doesn't you should be able to wrap <![CDATA[<stuff>]]> tags around you're input, and put it in as a text node.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    New Coder
    Join Date
    Jun 2008
    Posts
    76
    Thanks
    6
    Thanked 6 Times in 6 Posts
    I have tryed using the cdata block trick it still seems to come accross encoded either by XSLTProcessor or DOMDocument

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by kieran491 View Post
    I have tryed using the cdata block trick it still seems to come accross encoded either by XSLTProcessor or DOMDocument
    did you try this way?
    PHP Code:
    $Template->paragraph("<![CDATA[<strong>Welcome to Site, an Australian based game server provider.</strong>]]>"); 
    what extension did you use dom or dom xml and what php version?

    best regards

  • #7
    New Coder
    Join Date
    Jun 2008
    Posts
    76
    Thanks
    6
    Thanked 6 Times in 6 Posts
    i am using "PHP Version 5.2.6"
    and i am using DOM

    the actual code that turns the strings and array into xml is

    PHP Code:
        private function xml(){
            
    $document    $this->xml->createElement('document');
            
    $title        $this->xml->createElement('title',$this->title);
            
    $body        $this->xml->createElement('body');
            foreach(
    $this->paragraphs as $value){
                
    $paragraph $this->xml->createElement('paragraph',$value);
                
    $body->appendChild($paragraph);
            }
            
    $document->appendChild($title);
            
    $document->appendChild($body);
            
            foreach(
    $this->section as $Value){
                
    $document->appendChild($Value->output());
            }
            
    $this->xml->appendChild($document);
            return 
    $this->xml;
        } 
    and

    PHP Code:
        private function xml(){
            
    $section        $this->xml->createElement('section');
            
    $title            $this->xml->createElement('title',$this->title);
            
    $body            $this->xml->createElement('body');
            if(
    count($this->body) > 0){
                foreach(
    $this->body as $value){
                    
    $paragraph    $this->xml->createElement('paragraph',$value);
                    
    $body->appendChild($paragraph);
                }
            }else{
                
    $body->appendChild($this->xml->createElement('paragraph'));
            } 
    Last edited by kieran491; 12-18-2008 at 03:20 PM.

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    this is an example how you can use createCDATASection:
    PHP Code:
    <?php
    $doc 
    = new DOMDocument('1.0','utf-8');
    if(
    $doc){
      
    $doc->preserveWhiteSpace false;
      
    $doc->formatOutput   true;
      
    $node $doc->createElement('root');
      
    $doc->appendChild($node);
      
    // from here
      
    $cdata $doc->createCDATASection('<p>test</p>');
      
    $node->appendChild($cdata);
      echo 
    $doc->saveXML();
    }
    ?>
    seems that you can deal with that by your own,

    http://www.php.net/manual/en/domdocu...ateelement.php

    best regards

  • #9
    New Coder
    Join Date
    Jun 2008
    Posts
    76
    Thanks
    6
    Thanked 6 Times in 6 Posts
    I have updated the code to reflect the sugested ideas the output i get from php xml wise is

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <document><title>Welcome</title><body><paragraph><![CDATA[
    			<strong>
    				Welcome to Site, an Australian based game server provider.
    			</strong>
    			<br />
    			We supply the gaming community of Australia with high bandwidth, low latency quality servers at competitive prices.
    			<br />
    			We could say we are one of the best server providers in Australia, like all those other companies do but we believe in honesty at gExtreme. If there is a server problem, we won't beat around the bush, instead we will let you know and get it fixed right away!
    			<br />
    			<br /> 
    			Everyone wants the best server they can get for their money, but do you know what to look for? Contact our support team and let us know about the plans for your server and we will let you know what kind of services you require, whether we offer it or not.
    			<br />]]></paragraph></body><section template="index"><title>Test Document</title><body><paragraph><![CDATA[This is a simple test document.]]></paragraph><paragraph><![CDATA[Heres some more document that can be printed]]></paragraph></body></section></document>
    XSL wise though

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title></title><meta http-equiv="Content-Language" content="English"></meta><meta name="author" content=".com"></meta><meta name="description" content="counter strike source servers"></meta><meta name="keywords" content=",counter,strike,source,servers,australia,brisbane"></meta><meta name="Robots" content="index,follow"></meta><link rel="stylesheet" type="text/css" href="css/main.css" media="screen"></link></head><body><div id="hd"><ul><li id="logo"><a href="http://gextreme.com" title="Go to Home page">
    								
    							</a></li></ul></div><div id="ct"><div id="ctr"><dl><dt><strong>
    									Counter Strike:Source Special
    								</strong></dt><dd><br></br>
    								Get the "" tag removed from your server name
    								absolutely free if you signup now!
    								<br></br><span class="termsapply">
    									* Terms and conditions may apply
    								</span><br></br></dd></dl><h2>
    							Ping Test Server
    						</h2><ol><li><strong>
    
    									Server Name
    								</strong>
    								: .com // Ping Test
    							</li><li><strong>
    									Max Players
    								</strong>
    								: 4
    							</li><li><strong>
    									Map
    								</strong>
    								: de_aztec
    							</li></ol><div style="text-align: center"><a href="steam://connect/202.60.72.168:27015/"><strong>
    
    									Connect
    								</strong></a></div><br></br><h2>
    							Random Testimony
    						</h2><div style="text-align: center">
    							im surprised ur servers run my zombie mod server so good. ty
    							<br></br><br></br><span class="trueblack">
    								Written By: REC. John Doyle
    							</span></div></div><ul id="men"><li id="m1"><a href="index.php" title="" class="act">
    								Home
    							</a></li><li id="m2"><a href="forum.php" title="">
    								Forums
    							</a></li><li id="m3"><a href="order.php" title="">
    
    								Order
    							</a></li><li id="m4"><a href="faq.php" title="">
    								FAQ
    							</a></li><li id="m5"><a href="contact.php" title="">
    								Contact
    							</a></li></ul><div id="ctc"><h1>Welcome</h1><p><paragraph xmlns="">
    			&lt;strong&gt;
    				Welcome to Site, an Australian based game server provider.
    			&lt;/strong&gt;
    
    			&lt;br /&gt;
    			We supply the gaming community of Australia with high bandwidth, low latency quality servers at competitive prices.
    			&lt;br /&gt;
    			We could say we are one of the best server providers in Australia, like all those other companies do but we believe in honesty at gExtreme. If there is a server problem, we won't beat around the bush, instead we will let you know and get it fixed right away!
    			&lt;br /&gt;
    			&lt;br /&gt; 
    			Everyone wants the best server they can get for their money, but do you know what to look for? Contact our support team and let us know about the plans for your server and we will let you know what kind of services you require, whether we offer it or not.
    			&lt;br /&gt;</paragraph></p><h2 xmlns="">Test Document</h2>
    
    <p xmlns=""><paragraph>This is a simple test document.</paragraph></p>
    <p xmlns=""><paragraph>Heres some more document that can be printed</paragraph></p></div></div><div id="ft">
    					Copyright 2008 gExtreme.com. 
    				</div></body></html>
    PHP Code:
        private function xml(){
            
    $document    $this->xml->createElement('document');
            
    $title        $this->xml->createElement('title',$this->title);
            
    $body        $this->xml->createElement('body');
            foreach(
    $this->paragraphs as $value){
                
    $CDATA        $this->xml->createCDATASection($value);
                
    $paragraph    $this->xml->createElement('paragraph');
                
    $paragraph->appendChild($CDATA);
                
    $body->appendChild($paragraph);
            }
            
    $document->appendChild($title);
            
    $document->appendChild($body);
            
            foreach(
    $this->section as $Value){
                
    $document->appendChild($Value->output());
            }
            
    $this->xml->appendChild($document);
            return 
    $this->xml;
        } 
    PHP Code:
        private function xml(){
            
    $section        $this->xml->createElement('section');
            
    $title            $this->xml->createElement('title',$this->title);
            
    $body            $this->xml->createElement('body');
            if(
    count($this->body) > 0){
                foreach(
    $this->body as $value){
                    
    $CDATA        $this->xml->createCDATASection($value);
                    
    $paragraph    $this->xml->createElement('paragraph');
                    
    $paragraph->appendChild($CDATA);
                    
    $body->appendChild($paragraph);
                }
            }else{
                
    $body->appendChild($this->xml->createElement('paragraph'));
            }
            
            
    $section->setAttribute('template',$this->template);
            
    $section->appendChild($title);
            
    $section->appendChild($body);
            return 
    $section;
        } 
    I am still getting results that just dont make sence
    Last edited by kieran491; 12-18-2008 at 04:28 PM.

  • #10
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    xslt is guilty, If I remember you have disable-output-escaping="no", change it to yes and check again.

    best regards

  • #11
    New Coder
    Join Date
    Jun 2008
    Posts
    76
    Thanks
    6
    Thanked 6 Times in 6 Posts
    are we talking about http://au2.php.net/manual/en/book.xsl.php?

    i cant seem to find anywhere in the manual refering to that particular varible or function

  • #12
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by kieran491 View Post
    are we talking about http://au2.php.net/manual/en/book.xsl.php?

    i cant seem to find anywhere in the manual refering to that particular varible or function
    no, about you xslt file from your post in xml forum. I remember something like:
    Code:
    <xsl:value-of disable-output-escaping="..."
    you can use disable-output-escaping="yes" with both xsl:value-of and xsl:copy-of.

    The php output from your previous post seems ok.

    best regards

  • #13
    New Coder
    Join Date
    Jun 2008
    Posts
    76
    Thanks
    6
    Thanked 6 Times in 6 Posts
    I put the <xsl:copy-of select="." disable-output-escaping="yes" /> in there but i still get escaped charecters just like before

  • #14
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by kieran491 View Post
    I put the <xsl:copy-of select="." disable-output-escaping="yes" /> in there but i still get escaped charecters just like before
    what do you use to transform, transformToDoc or transformToXML?

    best regards

  • #15
    New Coder
    Join Date
    Jun 2008
    Posts
    76
    Thanks
    6
    Thanked 6 Times in 6 Posts
    i am using transformToXML

    PHP Code:
        public function __toString(){
            
    $XSLDom    = new DOMDocument();
            
    $XSLDom->load($this->path '/' $this->file '.xsl');
            
    $this->xsl->importStylesheet($XSLDom);
            return 
    $this->xsl->transformToXML($this->xml());
        } 
    To change the XML to a xhtml ouput
    Last edited by kieran491; 12-18-2008 at 06:22 PM.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •