Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > #32558 : formatOutput Problems
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 19th March 05:56
php-bugs
External User
 
Posts: 1
Default #32558 : formatOutput Problems



From: thomas dot werner at mac dot com
Operating system: Linux/OSX
PHP version: 5.0.4
PHP Bug Type: DOM XML related
Bug description: formatOutput Problems

Description:
------------


only created the object inside of my class.

but after adding of an element node, the cr/lf ist
missing.

a tried everything to get it work (

cheers tom

Reproduce code:
---------------
<?php

class CMS_XML {

var $convert = false;
var $formed = true;
var $encoding = "ISO-8859-1";

var $filename;

var $wddx = false;

var $_xml;
var $_debug;

var $_xpath;
var $_path;

function __construct( $debug = 0 ) {/*{{{*/
$this->_debug = $debug;
$this->convert = $convert;

}/*}}}*/

function _returnXML( $path, $value = array() )
{/*{{{*/
if ( is_array( $path ) && sizeof( $path ) ) {
$returnxml = array();
for( $i = 0; $i < sizeof( $path ); $i++ ) {
$returnxml[$i] = new ESMT_CORE_XML_ITEM( $this );
$returnxml[$i]->xpath = $path[$i];
if( isset( $value[$i] ) )
$returnxml[$i]->text = $value[$i];
}
}
else {
$returnxml = new ESMT_CORE_XML_ITEM( $this );
$returnxml->xpath = $path;
if( isset( $value ) )
$returnxml->value = $value;
}
return $returnxml;
}/*}}}*/

function _prepareXpath( $path )
{/*{{{*/

if( !is_string( $path ) ) {
die( 'XML FATAL ERROR: path is not a string ('.print_r( $path
).')!');
}
if ( preg_match_all("|(\/[^\[]+\[)([^\]'\"\s]+)(\])|", $path, $out ) )
{
for( $i = 0; $i < sizeof( $out[0] ); $i++ ) {
$path = str_replace( $out[1][$i].$out[2][$i].$out[3][$i],
$out[1][$i].preg_replace( '/([^=]+)=([^"\']+)/', "\\1='\\2'", $out[2][$i]
).$out[3][$i] ,$path );
}
}
if ( preg_match_all("|\/([a-zA-Z_:]+)\(([0-9]+)\)|", $path, $out ) ) {
for( $i = 0; $i < sizeof( $out[0] ); $i++ ) {
$path = str_replace( '/'.$out[1][$i].'('.$out[2][$i].')',
'/'.$out[1][$i].'['.( $out[2][$i] + 1 ).']', $path ); } }
#echo "<br>$path";

return $path;
}/*}}}*/

function _getXpath( $node, $path = '' )
{/*{{{*/

$index = 0;
if ( $node->parentNode ) {

$temp = $node;
while( $temp ) {
if ( $temp->nodeType == XML_ELEMENT_NODE ) {
if( $temp->nodeName == $node->nodeName )
{
$index++; } }
$temp = $temp->previousSibling; }
$path = ( "/" . $node->nodeName . "[" . $index . "]" . $path );
if( $node->parentNode ) {
$path = $this->_getXpath( $node->parentNode, $path );
}

unset( $temp );
}

return $path;

}/*}}}*/

function parseString( $string ) {/*{{{*/
$this->_xml = new domDo***ent();
$this->_xml->resolveExternals = true;
if ( !$this->_xml->loadXML( trim( $string ) ) ) {
unset( $this->_xml );

return false;
}

return $this;
}/*}}}*/

function parseFile( $filename, $trusted = false ) {/*{{{*/
$this->filename = ( !ereg( "/", $filename ) && is_file( ereg_replace(
"/$", "", $this->path )."/".$filename ) ) ? ereg_replace( "/$", "",
$this->path )."/".$filename : $filename;
if ( $trusted && !$this->trustedFile() ) { return false; }
if ( ! ( $filepointer = fopen( $this->filename, "r" ) ) ) {
return false;
}

$data = "";
while ( !feof( $filepointer) ) {
$data .= fgets( $filepointer, 4096 );
} fclose( $filepointer );
return $this->parseString( $data );
}/*}}}*/

function getDo***ent( $header = true, $formatted = true ) {/*{{{*/
if ( !is_object( $this->_xml ) ) return false;
if ( $formatted === true || $this->_debug ) {
$this->_xml->formatOutput = true;
}
if ( $header ) {
$doc = $this->_xml->saveXML(); } else {
if ( $this->_xml->lastChild ) {
$doc = $this->_xml->saveXML( $this->_xml->lastChild ); } }
if ( $this->_debug ) {
echo "XML Debug: getDo***ent [<pre>".htmlentities( $doc
)."</pre>]\n";
}

return $doc;

}/*}}}*/

function createNode( $path, $name ) {/*{{{*/
if ( $path == "" ) $path = $this->_path;
$path = $this->_prepareXpath( $path );
if ( !is_object( $this->_xml ) ) return false;
if ( !is_object( $this->_xpath ) )
$this->_xpath = new domXPath( $this->_xml );
if ( $nodes = $this->_xpath->query( $path ) ) {
if ( $nodes->length ) {
$xpath = array();
foreach( $nodes as $node ) {
if( $node->nodeType == XML_ELEMENT_NODE ) {
$foo = $node->appendChild( new domElement( $name ) );
if ( $nodes->length == 1 )
return $this->_returnXML( $this->_getXPath( $foo ) ); else
$xpath[] = $this->_getXPath( $foo ); } }
if( $xpath ) return $this->_returnXML( $xpath );
}
}

return null;
}/*}}}*/
}

class CMS_XSL extends CMS_XML {/*{{{*/

}/*}}}*/


class ESMT_CORE_XML_ITEM {/*{{{*/

var $xpath;
var $text;
var $value;

var $parent = false;

function __construct( $parent = false )
{/*{{{*/
if ( is_object( $parent ) ) {
$this->parent = $parent;
}
}/*}}}*/

}/*}}}*/

<?php

include( 'xml2.php' );

$xml = new CMS_XML();
$xml->parseFile( 'test.xml' );
$xml->createNode( '//struct', 'foo' );
echo "<pre>".htmlentities( $xml->getDo***ent() )."</pre>";
echo "FormatOuptut: ".( $xml->_xml->formatOutput ? 'true' : 'false' );
?> Expected result: ----------------
<?xml version="1.0"?>
<wddxpacket version="1.0">
<header>
<comment>idea::CMS Editor Configuration File</
comment>
</header>
<data>
<struct>
<var name="editor_versioning">
<number>25</number>
</var>
<var name="editor_console">
<number>25</number>
</var>
<var name="editor_caching">
<number>3</number>
</var>
<var name="editor_paste">
<string>false</string>
</var>
<var name="editor_styles">
<null/>
</var>
<foo/>
</struct>
</data>
</wddxpacket>

FormatOuptut: true Actual result: --------------
<?xml version="1.0"?>
<wddxpacket version="1.0">
<header>
<comment>idea::CMS Editor Configuration File</
comment>
</header>
<data>
<struct>
<var name="editor_versioning">
<number>25</number>
</var>
<var name="editor_console">
<number>25</number>
</var>
<var name="editor_caching">
<number>3</number>
</var>
<var name="editor_paste">
<string>false</string>
</var>
<var name="editor_styles">
<null/>
</var>
<foo/></struct>
</data>
</wddxpacket>

FormatOuptut: true

--
Edit bug report at http://bugs.php.net/?id=32558&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=32558&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=32558&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=32558&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=32558&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=32558&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=32558&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=32558&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=32558&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=32558&r=support
Expected behavior: http://bugs.php.net/fix.php?id=32558&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=32558&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=32558&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=32558&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=32558&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=32558&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=32558&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=32558&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=32558&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=32558&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=32558&r=mysqlcfg
  Reply With Quote


  sponsored links


2 19th March 05:56
External User
 
Posts: 1
Default #32558 : formatOutput Problems



ID: 32558
Updated by: tony2001@php.net
Reported By: thomas dot werner at mac dot com
-Status: Open
+Status: Feedback
Bug Type: DOM XML related
Operating System: Linux/OSX
PHP Version: 5.0.4
New Comment:

Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


Previous Comments:
------------------------------------------------------------------------

[2005-04-03 18:24:15] thomas dot werner at mac dot com

Description:
------------


only created the object inside of my class.

but after adding of an element node, the cr/lf ist
missing.

a tried everything to get it work (

cheers tom

Reproduce code:
---------------
<?php

class CMS_XML {

var $convert = false;
var $formed = true;
var $encoding = "ISO-8859-1";

var $filename;

var $wddx = false;

var $_xml;
var $_debug;

var $_xpath;
var $_path;

function __construct( $debug = 0 ) {/*{{{*/
$this->_debug = $debug;
$this->convert = $convert;

}/*}}}*/

function _returnXML( $path, $value = array() )
{/*{{{*/
if ( is_array( $path ) && sizeof( $path ) ) {
$returnxml = array();
for( $i = 0; $i < sizeof( $path ); $i++ ) {
$returnxml[$i] = new ESMT_CORE_XML_ITEM( $this );
$returnxml[$i]->xpath = $path[$i];
if( isset( $value[$i] ) )
$returnxml[$i]->text = $value[$i];
}
}
else {
$returnxml = new ESMT_CORE_XML_ITEM( $this );
$returnxml->xpath = $path;
if( isset( $value ) )
$returnxml->value = $value;
}
return $returnxml;
}/*}}}*/

function _prepareXpath( $path )
{/*{{{*/

if( !is_string( $path ) ) {
die( 'XML FATAL ERROR: path is not a string ('.print_r( $path
).')!');
}
if ( preg_match_all("|(\/[^\[]+\[)([^\]'\"\s]+)(\])|", $path, $out )
) {
for( $i = 0; $i < sizeof( $out[0] ); $i++ ) {
$path = str_replace( $out[1][$i].$out[2][$i].$out[3][$i],
$out[1][$i].preg_replace( '/([^=]+)=([^"\']+)/', "\\1='\\2'",
$out[2][$i] ).$out[3][$i] ,$path );
}
}
if ( preg_match_all("|\/([a-zA-Z_:]+)\(([0-9]+)\)|", $path, $out ) )
{
for( $i = 0; $i < sizeof( $out[0] ); $i++ ) {
$path = str_replace( '/'.$out[1][$i].'('.$out[2][$i].')',
'/'.$out[1][$i].'['.( $out[2][$i] + 1 ).']', $path ); } }
#echo "<br>$path";

return $path;
}/*}}}*/

function _getXpath( $node, $path = '' )
{/*{{{*/

$index = 0;
if ( $node->parentNode ) {

$temp = $node;
while( $temp ) {
if ( $temp->nodeType == XML_ELEMENT_NODE ) {
if( $temp->nodeName == $node->nodeName )
{
$index++; } }
$temp = $temp->previousSibling; }
$path = ( "/" . $node->nodeName . "[" . $index . "]" . $path );
if( $node->parentNode ) {
$path = $this->_getXpath( $node->parentNode, $path );
}

unset( $temp );
}

return $path;

}/*}}}*/

function parseString( $string ) {/*{{{*/
$this->_xml = new domDo***ent();
$this->_xml->resolveExternals = true;
if ( !$this->_xml->loadXML( trim( $string ) ) ) {
unset( $this->_xml );

return false;
}

return $this;
}/*}}}*/

function parseFile( $filename, $trusted = false ) {/*{{{*/
$this->filename = ( !ereg( "/", $filename ) && is_file(
ereg_replace( "/$", "", $this->path )."/".$filename ) ) ? ereg_replace(
"/$", "", $this->path )."/".$filename : $filename;
if ( $trusted && !$this->trustedFile() ) { return false; }
if ( ! ( $filepointer = fopen( $this->filename, "r" ) ) ) {
return false;
}

$data = "";
while ( !feof( $filepointer) ) {
$data .= fgets( $filepointer, 4096 );
} fclose( $filepointer );
return $this->parseString( $data );
}/*}}}*/

function getDo***ent( $header = true, $formatted = true ) {/*{{{*/
if ( !is_object( $this->_xml ) ) return false;
if ( $formatted === true || $this->_debug ) {
$this->_xml->formatOutput = true;
}
if ( $header ) {
$doc = $this->_xml->saveXML(); } else {
if ( $this->_xml->lastChild ) {
$doc = $this->_xml->saveXML( $this->_xml->lastChild ); } }
if ( $this->_debug ) {
echo "XML Debug: getDo***ent [<pre>".htmlentities( $doc
)."</pre>]\n";
}

return $doc;

}/*}}}*/

function createNode( $path, $name ) {/*{{{*/
if ( $path == "" ) $path = $this->_path;
$path = $this->_prepareXpath( $path );
if ( !is_object( $this->_xml ) ) return false;
if ( !is_object( $this->_xpath ) )
$this->_xpath = new domXPath( $this->_xml );
if ( $nodes = $this->_xpath->query( $path ) ) {
if ( $nodes->length ) {
$xpath = array();
foreach( $nodes as $node ) {
if( $node->nodeType == XML_ELEMENT_NODE ) {
$foo = $node->appendChild( new domElement( $name ) );
if ( $nodes->length == 1 )
return $this->_returnXML( $this->_getXPath( $foo ) ); else
$xpath[] = $this->_getXPath( $foo ); } }
if( $xpath ) return $this->_returnXML( $xpath );
}
}

return null;
}/*}}}*/
}

class CMS_XSL extends CMS_XML {/*{{{*/

}/*}}}*/


class ESMT_CORE_XML_ITEM {/*{{{*/

var $xpath;
var $text;
var $value;

var $parent = false;

function __construct( $parent = false )
{/*{{{*/
if ( is_object( $parent ) ) {
$this->parent = $parent;
}
}/*}}}*/

}/*}}}*/

<?php

include( 'xml2.php' );

$xml = new CMS_XML();
$xml->parseFile( 'test.xml' );
$xml->createNode( '//struct', 'foo' );
echo "<pre>".htmlentities( $xml->getDo***ent() )."</pre>";
echo "FormatOuptut: ".( $xml->_xml->formatOutput ? 'true' : 'false' );
?> Expected result: ----------------
<?xml version="1.0"?>
<wddxpacket version="1.0">
<header>
<comment>idea::CMS Editor Configuration File</
comment>
</header>
<data>
<struct>
<var name="editor_versioning">
<number>25</number>
</var>
<var name="editor_console">
<number>25</number>
</var>
<var name="editor_caching">
<number>3</number>
</var>
<var name="editor_paste">
<string>false</string>
</var>
<var name="editor_styles">
<null/>
</var>
<foo/>
</struct>
</data>
</wddxpacket>

FormatOuptut: true Actual result: --------------
<?xml version="1.0"?>
<wddxpacket version="1.0">
<header>
<comment>idea::CMS Editor Configuration File</
comment>
</header>
<data>
<struct>
<var name="editor_versioning">
<number>25</number>
</var>
<var name="editor_console">
<number>25</number>
</var>
<var name="editor_caching">
<number>3</number>
</var>
<var name="editor_paste">
<string>false</string>
</var>
<var name="editor_styles">
<null/>
</var>
<foo/></struct>
</data>
</wddxpacket>

FormatOuptut: true


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=32558&edit=1
  Reply With Quote
3 19th March 05:56
php-bugs
External User
 
Posts: 1
Default #32558 : formatOutput Problems


ID: 32558
User updated by: thomas dot werner at mac dot com
Reported By: thomas dot werner at mac dot com
-Status: Feedback
+Status: Open
Bug Type: DOM XML related
Operating System: Linux/OSX
PHP Version: 5.0.4
New Comment:

sorry for the long code, but a have only this example:

working example with php5.0.3:
http://213.61.134.141/32558.php
source code:
http://213.61.134.141/32558.txt

http://213.61.134.141/phpinfo.php

i think the parseString and the getDo***ent methods in
my class is the important point. i set it there without
any success.

cheers tom


Previous Comments:
------------------------------------------------------------------------

[2005-04-03 18:26:33] tony2001@php.net

Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.

------------------------------------------------------------------------

[2005-04-03 18:24:15] thomas dot werner at mac dot com

Description:
------------


only created the object inside of my class.

but after adding of an element node, the cr/lf ist
missing.

a tried everything to get it work (

cheers tom

Reproduce code:
---------------
<?php

class CMS_XML {

var $convert = false;
var $formed = true;
var $encoding = "ISO-8859-1";

var $filename;

var $wddx = false;

var $_xml;
var $_debug;

var $_xpath;
var $_path;

function __construct( $debug = 0 ) {/*{{{*/
$this->_debug = $debug;
$this->convert = $convert;

}/*}}}*/

function _returnXML( $path, $value = array() )
{/*{{{*/
if ( is_array( $path ) && sizeof( $path ) ) {
$returnxml = array();
for( $i = 0; $i < sizeof( $path ); $i++ ) {
$returnxml[$i] = new ESMT_CORE_XML_ITEM( $this );
$returnxml[$i]->xpath = $path[$i];
if( isset( $value[$i] ) )
$returnxml[$i]->text = $value[$i];
}
}
else {
$returnxml = new ESMT_CORE_XML_ITEM( $this );
$returnxml->xpath = $path;
if( isset( $value ) )
$returnxml->value = $value;
}
return $returnxml;
}/*}}}*/

function _prepareXpath( $path )
{/*{{{*/

if( !is_string( $path ) ) {
die( 'XML FATAL ERROR: path is not a string ('.print_r( $path
).')!');
}
if ( preg_match_all("|(\/[^\[]+\[)([^\]'\"\s]+)(\])|", $path, $out )
) {
for( $i = 0; $i < sizeof( $out[0] ); $i++ ) {
$path = str_replace( $out[1][$i].$out[2][$i].$out[3][$i],
$out[1][$i].preg_replace( '/([^=]+)=([^"\']+)/', "\\1='\\2'",
$out[2][$i] ).$out[3][$i] ,$path );
}
}
if ( preg_match_all("|\/([a-zA-Z_:]+)\(([0-9]+)\)|", $path, $out ) )
{
for( $i = 0; $i < sizeof( $out[0] ); $i++ ) {
$path = str_replace( '/'.$out[1][$i].'('.$out[2][$i].')',
'/'.$out[1][$i].'['.( $out[2][$i] + 1 ).']', $path ); } }
#echo "<br>$path";

return $path;
}/*}}}*/

function _getXpath( $node, $path = '' )
{/*{{{*/

$index = 0;
if ( $node->parentNode ) {

$temp = $node;
while( $temp ) {
if ( $temp->nodeType == XML_ELEMENT_NODE ) {
if( $temp->nodeName == $node->nodeName )
{
$index++; } }
$temp = $temp->previousSibling; }
$path = ( "/" . $node->nodeName . "[" . $index . "]" . $path );
if( $node->parentNode ) {
$path = $this->_getXpath( $node->parentNode, $path );
}

unset( $temp );
}

return $path;

}/*}}}*/

function parseString( $string ) {/*{{{*/
$this->_xml = new domDo***ent();
$this->_xml->resolveExternals = true;
if ( !$this->_xml->loadXML( trim( $string ) ) ) {
unset( $this->_xml );

return false;
}

return $this;
}/*}}}*/

function parseFile( $filename, $trusted = false ) {/*{{{*/
$this->filename = ( !ereg( "/", $filename ) && is_file(
ereg_replace( "/$", "", $this->path )."/".$filename ) ) ? ereg_replace(
"/$", "", $this->path )."/".$filename : $filename;
if ( $trusted && !$this->trustedFile() ) { return false; }
if ( ! ( $filepointer = fopen( $this->filename, "r" ) ) ) {
return false;
}

$data = "";
while ( !feof( $filepointer) ) {
$data .= fgets( $filepointer, 4096 );
} fclose( $filepointer );
return $this->parseString( $data );
}/*}}}*/

function getDo***ent( $header = true, $formatted = true ) {/*{{{*/
if ( !is_object( $this->_xml ) ) return false;
if ( $formatted === true || $this->_debug ) {
$this->_xml->formatOutput = true;
}
if ( $header ) {
$doc = $this->_xml->saveXML(); } else {
if ( $this->_xml->lastChild ) {
$doc = $this->_xml->saveXML( $this->_xml->lastChild ); } }
if ( $this->_debug ) {
echo "XML Debug: getDo***ent [<pre>".htmlentities( $doc
)."</pre>]\n";
}

return $doc;

}/*}}}*/

function createNode( $path, $name ) {/*{{{*/
if ( $path == "" ) $path = $this->_path;
$path = $this->_prepareXpath( $path );
if ( !is_object( $this->_xml ) ) return false;
if ( !is_object( $this->_xpath ) )
$this->_xpath = new domXPath( $this->_xml );
if ( $nodes = $this->_xpath->query( $path ) ) {
if ( $nodes->length ) {
$xpath = array();
foreach( $nodes as $node ) {
if( $node->nodeType == XML_ELEMENT_NODE ) {
$foo = $node->appendChild( new domElement( $name ) );
if ( $nodes->length == 1 )
return $this->_returnXML( $this->_getXPath( $foo ) ); else
$xpath[] = $this->_getXPath( $foo ); } }
if( $xpath ) return $this->_returnXML( $xpath );
}
}

return null;
}/*}}}*/
}

class CMS_XSL extends CMS_XML {/*{{{*/

}/*}}}*/


class ESMT_CORE_XML_ITEM {/*{{{*/

var $xpath;
var $text;
var $value;

var $parent = false;

function __construct( $parent = false )
{/*{{{*/
if ( is_object( $parent ) ) {
$this->parent = $parent;
}
}/*}}}*/

}/*}}}*/

<?php

include( 'xml2.php' );

$xml = new CMS_XML();
$xml->parseFile( 'test.xml' );
$xml->createNode( '//struct', 'foo' );
echo "<pre>".htmlentities( $xml->getDo***ent() )."</pre>";
echo "FormatOuptut: ".( $xml->_xml->formatOutput ? 'true' : 'false' );
?> Expected result: ----------------
<?xml version="1.0"?>
<wddxpacket version="1.0">
<header>
<comment>idea::CMS Editor Configuration File</
comment>
</header>
<data>
<struct>
<var name="editor_versioning">
<number>25</number>
</var>
<var name="editor_console">
<number>25</number>
</var>
<var name="editor_caching">
<number>3</number>
</var>
<var name="editor_paste">
<string>false</string>
</var>
<var name="editor_styles">
<null/>
</var>
<foo/>
</struct>
</data>
</wddxpacket>

FormatOuptut: true Actual result: --------------
<?xml version="1.0"?>
<wddxpacket version="1.0">
<header>
<comment>idea::CMS Editor Configuration File</
comment>
</header>
<data>
<struct>
<var name="editor_versioning">
<number>25</number>
</var>
<var name="editor_console">
<number>25</number>
</var>
<var name="editor_caching">
<number>3</number>
</var>
<var name="editor_paste">
<string>false</string>
</var>
<var name="editor_styles">
<null/>
</var>
<foo/></struct>
</data>
</wddxpacket>

FormatOuptut: true


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=32558&edit=1
  Reply With Quote
4 22nd March 05:17
php-bugs
External User
 
Posts: 1
Default #32558 : formatOutput Problems


ID: 32558
User updated by: thomas dot werner at mac dot com
Reported By: thomas dot werner at mac dot com
Status: Bogus
Bug Type: DOM XML related
Operating System: Linux/OSX
PHP Version: 5.0.4
New Comment:

sorry! it will never happen again, it could be my
fault... and thank your for your 'help'.


Previous Comments:
------------------------------------------------------------------------

[2005-04-03 22:52:23] sniper@php.net

Try putting some effort into this yourself, we're not here to fix your
code.


------------------------------------------------------------------------

[2005-04-03 20:21:49] thomas dot werner at mac dot com

sorry for the long code, but a have only this example:

working example with php5.0.3:
http://213.61.134.141/32558.php
source code:
http://213.61.134.141/32558.txt

http://213.61.134.141/phpinfo.php

i think the parseString and the getDo***ent methods in
my class is the important point. i set it there without
any success.

cheers tom

------------------------------------------------------------------------

[2005-04-03 18:26:33] tony2001@php.net

Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.

------------------------------------------------------------------------

[2005-04-03 18:24:15] thomas dot werner at mac dot com

Description:
------------


only created the object inside of my class.

but after adding of an element node, the cr/lf ist
missing.

a tried everything to get it work (

cheers tom

Reproduce code:
---------------
<?php

class CMS_XML {

var $convert = false;
var $formed = true;
var $encoding = "ISO-8859-1";

var $filename;

var $wddx = false;

var $_xml;
var $_debug;

var $_xpath;
var $_path;

function __construct( $debug = 0 ) {/*{{{*/
$this->_debug = $debug;
$this->convert = $convert;

}/*}}}*/

function _returnXML( $path, $value = array() )
{/*{{{*/
if ( is_array( $path ) && sizeof( $path ) ) {
$returnxml = array();
for( $i = 0; $i < sizeof( $path ); $i++ ) {
$returnxml[$i] = new ESMT_CORE_XML_ITEM( $this );
$returnxml[$i]->xpath = $path[$i];
if( isset( $value[$i] ) )
$returnxml[$i]->text = $value[$i];
}
}
else {
$returnxml = new ESMT_CORE_XML_ITEM( $this );
$returnxml->xpath = $path;
if( isset( $value ) )
$returnxml->value = $value;
}
return $returnxml;
}/*}}}*/

function _prepareXpath( $path )
{/*{{{*/

if( !is_string( $path ) ) {
die( 'XML FATAL ERROR: path is not a string ('.print_r( $path
).')!');
}
if ( preg_match_all("|(\/[^\[]+\[)([^\]'\"\s]+)(\])|", $path, $out )
) {
for( $i = 0; $i < sizeof( $out[0] ); $i++ ) {
$path = str_replace( $out[1][$i].$out[2][$i].$out[3][$i],
$out[1][$i].preg_replace( '/([^=]+)=([^"\']+)/', "\\1='\\2'",
$out[2][$i] ).$out[3][$i] ,$path );
}
}
if ( preg_match_all("|\/([a-zA-Z_:]+)\(([0-9]+)\)|", $path, $out ) )
{
for( $i = 0; $i < sizeof( $out[0] ); $i++ ) {
$path = str_replace( '/'.$out[1][$i].'('.$out[2][$i].')',
'/'.$out[1][$i].'['.( $out[2][$i] + 1 ).']', $path ); } }
#echo "<br>$path";

return $path;
}/*}}}*/

function _getXpath( $node, $path = '' )
{/*{{{*/

$index = 0;
if ( $node->parentNode ) {

$temp = $node;
while( $temp ) {
if ( $temp->nodeType == XML_ELEMENT_NODE ) {
if( $temp->nodeName == $node->nodeName )
{
$index++; } }
$temp = $temp->previousSibling; }
$path = ( "/" . $node->nodeName . "[" . $index . "]" . $path );
if( $node->parentNode ) {
$path = $this->_getXpath( $node->parentNode, $path );
}

unset( $temp );
}

return $path;

}/*}}}*/

function parseString( $string ) {/*{{{*/
$this->_xml = new domDo***ent();
$this->_xml->resolveExternals = true;
if ( !$this->_xml->loadXML( trim( $string ) ) ) {
unset( $this->_xml );

return false;
}

return $this;
}/*}}}*/

function parseFile( $filename, $trusted = false ) {/*{{{*/
$this->filename = ( !ereg( "/", $filename ) && is_file(
ereg_replace( "/$", "", $this->path )."/".$filename ) ) ? ereg_replace(
"/$", "", $this->path )."/".$filename : $filename;
if ( $trusted && !$this->trustedFile() ) { return false; }
if ( ! ( $filepointer = fopen( $this->filename, "r" ) ) ) {
return false;
}

$data = "";
while ( !feof( $filepointer) ) {
$data .= fgets( $filepointer, 4096 );
} fclose( $filepointer );
return $this->parseString( $data );
}/*}}}*/

function getDo***ent( $header = true, $formatted = true ) {/*{{{*/
if ( !is_object( $this->_xml ) ) return false;
if ( $formatted === true || $this->_debug ) {
$this->_xml->formatOutput = true;
}
if ( $header ) {
$doc = $this->_xml->saveXML(); } else {
if ( $this->_xml->lastChild ) {
$doc = $this->_xml->saveXML( $this->_xml->lastChild ); } }
if ( $this->_debug ) {
echo "XML Debug: getDo***ent [<pre>".htmlentities( $doc
)."</pre>]\n";
}

return $doc;

}/*}}}*/

function createNode( $path, $name ) {/*{{{*/
if ( $path == "" ) $path = $this->_path;
$path = $this->_prepareXpath( $path );
if ( !is_object( $this->_xml ) ) return false;
if ( !is_object( $this->_xpath ) )
$this->_xpath = new domXPath( $this->_xml );
if ( $nodes = $this->_xpath->query( $path ) ) {
if ( $nodes->length ) {
$xpath = array();
foreach( $nodes as $node ) {
if( $node->nodeType == XML_ELEMENT_NODE ) {
$foo = $node->appendChild( new domElement( $name ) );
if ( $nodes->length == 1 )
return $this->_returnXML( $this->_getXPath( $foo ) ); else
$xpath[] = $this->_getXPath( $foo ); } }
if( $xpath ) return $this->_returnXML( $xpath );
}
}

return null;
}/*}}}*/
}

class CMS_XSL extends CMS_XML {/*{{{*/

}/*}}}*/


class ESMT_CORE_XML_ITEM {/*{{{*/

var $xpath;
var $text;
var $value;

var $parent = false;

function __construct( $parent = false )
{/*{{{*/
if ( is_object( $parent ) ) {
$this->parent = $parent;
}
}/*}}}*/

}/*}}}*/

<?php

include( 'xml2.php' );

$xml = new CMS_XML();
$xml->parseFile( 'test.xml' );
$xml->createNode( '//struct', 'foo' );
echo "<pre>".htmlentities( $xml->getDo***ent() )."</pre>";
echo "FormatOuptut: ".( $xml->_xml->formatOutput ? 'true' : 'false' );
?> Expected result: ----------------
<?xml version="1.0"?>
<wddxpacket version="1.0">
<header>
<comment>idea::CMS Editor Configuration File</
comment>
</header>
<data>
<struct>
<var name="editor_versioning">
<number>25</number>
</var>
<var name="editor_console">
<number>25</number>
</var>
<var name="editor_caching">
<number>3</number>
</var>
<var name="editor_paste">
<string>false</string>
</var>
<var name="editor_styles">
<null/>
</var>
<foo/>
</struct>
</data>
</wddxpacket>

FormatOuptut: true Actual result: --------------
<?xml version="1.0"?>
<wddxpacket version="1.0">
<header>
<comment>idea::CMS Editor Configuration File</
comment>
</header>
<data>
<struct>
<var name="editor_versioning">
<number>25</number>
</var>
<var name="editor_console">
<number>25</number>
</var>
<var name="editor_caching">
<number>3</number>
</var>
<var name="editor_paste">
<string>false</string>
</var>
<var name="editor_styles">
<null/>
</var>
<foo/></struct>
</data>
</wddxpacket>

FormatOuptut: true


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=32558&edit=1
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666