Monday, January 26, 2009

Re: How can I get the xml encoding using Xml class?

Thanks RoVo,
I was on that path but stopped when my personal needs ended with the
knowledge that all text is converted on parsing.
But if I want to read an xml file and then save it back out again I
would definitely like to k ow the encoding so that the saved file
would have the same encoding as the original.

/Martin


On Jan 22, 10:22 pm, RoVo <rol...@service-itzehoe.de> wrote:
> Hi Martin,
>
> you are right! Better to search for the '>', not for "\n"
>
> My imaginable solution may be like this way - put the attributes to an
> array...
>
> $this->__header = trim( str_replace( a( '<'.'?', '?'.'>' ), a('', ''),
> substr(trim($this->__rawData), 0, strpos(trim($this->__rawData),
> '?'.'>') )));
> /**
>  *  find the attributes and attributes2array
>  */
> preg_match_all("/\ (.*)\=\"(.*)\"/iU", $this->__header, $attrib_arr,
> PREG_SET_ORDER);
> $this->__header_attributes = array();
> foreach ($attrib_arr as $found) {
>     if ( (isset($found[1])) AND (isset($found[2])) ) {
>         $this->__header_attributes[($found[1])] = $found[2];
>     }}
>
> ...
> debug( $this->__header_attributes );
> ...
>
> result of "$this->__header" after your modified "str_replace":
> xml version="1.0" encoding="UTF-8"
>
> result: preg_match_all
> Array
> (
>     [0] => Array
>         (
>             [0] =>  version="1.0"
>             [1] => version
>             [2] => 1.0
>         )
>
>     [1] => Array
>         (
>             [0] =>  encoding="UTF-8"
>             [1] => encoding
>             [2] => UTF-8
>         )
> )
>
> result: $this->__header_attributes
> Array
> (
>     [version] => 1.0
>     [encoding] => UTF-8
> )
>
> RoVo (c:
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: