RE: [PHP] LIBXML- Auto-Indent - How do it?

2001-12-17 Thread Christian Stocker

In <100984FEB15DD511BA9300104B6980760AC36B@EXCHANGE-RIO>, Ricardo Junior
wrote:

> The conversion to plain text mail format changed the correct indent that
> I need I'm needing it like this:
> 
> 
>   
> 
>   
> 
> 
> Thanks !!!

no need to scream here :)

here's a function, which maybe helps you (it adds indentation to a string
containing xml-stuff)

 function get_indented_xml($xml,$instring = "") {
$xml = preg_replace("/(\>)\n/","$1",$xml);
$xml = preg_replace("/\>\s*\\n<",$xml);

$axml = explode("\n",$xml);

$indent=-1;
$xmls = "";
foreach ($axml as $key => $value) {

if (preg_match("/<[^\/{1}]/",$value)) {
$indent++;
}
if ($indent < 0)
$indent = 0;
$xmls .= str_repeat($instring,$indent);
if (preg_match("/\<\//",$value) || preg_match("/\/\>/",$value)|| 
preg_match("/-->/",$value)) {
$indent--;
}
$xmls .= trim($value)."\n";
}
   return $xmls;
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] LIBXML- Auto-Indent - How do it?

2001-12-17 Thread Christian Stocker

In <100984FEB15DD511BA9300104B6980760AC36B@EXCHANGE-RIO>, Ricardo Junior
wrote:

> The conversion to plain text mail format changed the correct indent that
> I need I'm needing it like this:
>
> 
>   
> 
>   
> 
>
> Thanks !!!

no need to scream here :)

here's a function, which maybe helps you (it adds indentation to a string
containing xml-stuff)

 function get_indented_xml($xml,$instring = "") {
$xml = preg_replace("/(\>)\n/","$1",$xml);
$xml = preg_replace("/\>\s*\\n<",$xml);

$axml = explode("\n",$xml);

$indent=-1;
$xmls = "";
foreach ($axml as $key => $value) {

if (preg_match("/<[^\/{1}]/",$value)) {
$indent++;
}
if ($indent < 0)
$indent = 0;
$xmls .= str_repeat($instring,$indent);
if (preg_match("/\<\//",$value) ||
preg_match("/\/\>/",$value)|| preg_match("/-->/",$value)) {
$indent--;
}
$xmls .= trim($value)."\n";
}
   return $xmls;
}



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] LIBXML- Auto-Indent - How do it?

2001-12-17 Thread Junior, Ricardo

The conversion to plain text mail format changed the correct indent that I
need I'm needing it like this:


  

  


Thanks !!!

_
Ricardo J. A. Júnior, Software Engineer Trainee
Bowne Global Solutions

Phone   +55 21 2515 7713
[EMAIL PROTECTED]
www.bowneglobal.com.br

 -Original Message-
From:   Junior, Ricardo [mailto:[EMAIL PROTECTED]] 
Sent:   Monday, December 17, 2001 10:48 AM
To: '[EMAIL PROTECTED]'
Subject:[PHP] LIBXML- Auto-Indent - How do it?

Hi All,
I would like to know if there is any way to auto-indent the XML file when I
add a new node in a docxml object and export the string of the created XML
file with dumpmem() function...

For example:
$new = new_xmldoc("1.0");
$root = $new->add_root("ROOT");
$level1 = $root->new_child("LEVEL-1", "");
$level1->new_child("LEVEL2", "");
$new_xml_file = fopen ("test.xml", "w");
fwrite($new_xml_file, $new->dumpmem());
fclose ($new_xml_file);

The result in test.xml file is:
 

But I'm needing it like this: 











Could someone help me on this?!
Thanks. 
_
Ricardo J. A. Júnior, Software Engineer Trainee
Bowne Global Solutions

Phone   +55 21 2515 7713
[EMAIL PROTECTED] 

www.bowneglobal.com.br  


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]