2

Jun 21, 2016 am 09:09 AM
nbsp quot this

    {
        $this->doXmlString2Xml($string,$xpath);
    }

    /**
    * Adds an additional pear::db_result resultset to $this->xmldoc
    *
    * @param    Object db_result result from a DB-query
    * @see      doSql2Xml()
    * @access   public
    */
    function addResult($result)
    {
        $this->doSql2Xml($result);
    }

    /**
    * Adds an aditional resultset generated from an sql-statement
    *  to $this->xmldoc
    *
    * @param    string sql a string containing an sql-statement.
    * @access   public
    * @see      doSql2Xml()
    */
    function addSql($sql)
    {
        /* if there are {} expressions in the sql query, we assume it's an xpath expression to
        *   be evaluated.
        */

        if (preg_match_all ("/\{([^\}]+)\}/i",$sql,$matches))
        {
            foreach ($matches[1] as $match)
            {
                $sql = preg_replace("#\{".preg_quote($match)."\}#  ", $this->getXpathValue($match),$sql);
            }
        }
        $result = $this->db->query($sql);

        //very strange
        if (PEAR::isError($result->result)) {
                 print "You have an SQL-Error:
".$result->result->userinfo;
                 print "
";
                new DB_Error($result->result->code,PEAR_ERROR_DIE);
        }

        $this->doSql2Xml($result);
    }

    /**
    * Adds an aditional resultset generated from an Array
    *  to $this->xmldoc
    * TODO: more explanation, how arrays are transferred
    *
    * @param    array multidimensional array.
    * @access   public
    * @see      doArray2Xml()
    */
    function addArray ($array)
    {
        $parent_row = $this->insertNewResult(&$metadata);
        $this->DoArray2Xml($array,$parent_row);
    }

    /**
    * Returns an xml-string with a xml-representation of the resultsets.
    *
    * The resultset can be directly provided here, or if you need more than one
    * in your xml, then you have to provide each of them with add() before you
    * call getXML, but the last one can also be provided here.
    *
    * @param    mixed  $result result Object from a DB-query
    * @return   string  xml
    * @access   public
    */
    function getXML($result = Null)
    {
        $xmldoc = $this->getXMLObject($result);
        return $xmldoc->dumpmem();
    }

    /**
    * Returns an xml DomDocument Object with a xml-representation of the resultsets.
    *
    * The resultset can be directly provided here, or if you need more than one
    * in your xml, then you have to provide each of them with add() before you
    * call getXMLObject, but the last one can also be provided here.
    *
    * @param    mixed $result result Object from a DB-query
    * @return   Object DomDocument
    * @access   public
    */
    function getXMLObject($result = Null)
    {
        if ($result) {
            $this->add ($result);
        }
        return $this->xmldoc;
    }

    /**
    * For adding db_result-"trees" to $this->xmldoc
    * @param    Object db_result
    * @access   private
    * @see      addResult(),addSql()
    */
    function doSql2Xml($result)
    {

        if (DB::IsError($result)) {
            print "Error in file ".__FILE__." at line ".__LINE__."
\n";
            print $result->userinfo."
\n";
            new DB_Error($result->code,PEAR_ERROR_DIE);
        }

        // the method_exists is here, cause tableInfo is only in the cvs at the moment
        // BE CAREFUL: if you have fields with the same name in different tables, you will get errors
        // later, since DB_FETCHMODE_ASSOC doesn't differentiate that stuff.
        $this->LastResult = &$result;

        if (!method_exists($result,"tableInfo") || ! ($tableInfo = $result->tableInfo(False)))
        {
            //emulate tableInfo. this can go away, if every db supports tableInfo
            $fetchmode = DB_FETCHMODE_ASSOC;
            $res = $result->FetchRow($fetchmode);
            $this->nested = False;
            $i = 0;

            while (list($key, $val) = each($res))
            {
                $tableInfo[$i]["table"]= $this->tagNameResult;
                $tableInfo[$i]["name"] = $key;
                $resFirstRow[$i] = $val;
                $i++;
            }
            $res  = $resFirstRow;
            $FirstFetchDone = True;
            $fetchmode = DB_FETCHMODE_ORDERED;
        }
        else
        {
            $FirstFetchDone = False;
            $fetchmode = DB_FETCHMODE_ORDERED;
        }

        // initialize db hierarchy...
        $parenttable = "root";
        $tableInfo["parent_key"]["root"] = 0;

        foreach ($tableInfo as $key => $value)
        {
            if (is_int($key))
            {
                // if the sql-query had a function the table starts with a # (only in mysql i think....), then give the field the name of the table before...
                if (preg_match ("/^#/",$value["table"]) || strlen($value["table"]) == 0) {
                     $value["table"] = $tableInfo[($key - 1)]["table"] ;
                    $tableInfo[$key]["table"] = $value["table"];
                }


                if (!isset($tableInfo["parent_table"]) || is_null($tableInfo["parent_table"][$value]["table"]]))
                {
                    $tableInfo["parent_key"][$value]["table"]] = $key;
                    $tableInfo["parent_table"][$value]["table"]] = $parenttable;
                    $parenttable = $value["table"] ;
                }

            }
            //if you need more tableInfo for later use you can write a function addTableInfo..
            $this->addTableInfo($key, $value, &$tableInfo);
        }

        // end initialize

        // if user made some own tableInfo data, merge them here.
        if ($this->user_tableInfo)
        {
            $tableInfo = $this->array_merge_clobber($tableInfo,$this->user_tableInfo);
        }
        $parent['root'] = $this->insertNewResult(&$tableInfo);

        //initialize $resold to get rid of warning messages;
        $resold[0] = "ThisValueIsImpossibleForTheFirstFieldInTheFirstRow";

        while ($FirstFetchDone == True || $res = $result->FetchRow($fetchmode))
        {

            //FirstFetchDone is only for emulating tableInfo, as long as not all dbs support tableInfo. can go away later
            $FirstFetchDone = False;

            while (list($key, $val) = each($res))
            {

                if ($resold[$tableInfo]["parent_key"][$tableInfo][$key]["table"]]] != $res[$tableInfo]["parent_key"][$tableInfo][$key]["table"]]] || !$this->nested)
                {
                    if ($tableInfo["parent_key"][$tableInfo][$key]["table"]] == $key )
                    {
                        if ($this->nested || $key == 0)
                        {

                            $parent[$tableInfo][$key]["table"]] =  $this->insertNewRow($parent[$tableInfo]["parent_table"][$tableInfo][$key]["table"]]], $res, $key, &$tableInfo);
                        }
                        else
                        {
                            $parent[$tableInfo][$key]["table"]]= $parent[$tableInfo]["parent_table"][$tableInfo][$key]["table"]]];
                        }

                        //set all children entries to somethin stupid
                        foreach($tableInfo["parent_table"] as $pkey => $pvalue)
                        {
                            if ($pvalue == $tableInfo[$key]["table"])
                            {
                                $resold[$tableInfo]["parent_key"][$pkey]]= "ThisIsJustAPlaceHolder";
                            }
                        }

                    }
                    if ( $parent[$tableInfo][$key]["table"]] != Null)
                    {
                        $this->insertNewElement($parent[$tableInfo][$key]["table"]], $res, $key, &$tableInfo, &$subrow);
                    }

                }
            }

            $resold = $res;
            unset ($subrow);
        }
        return $this->xmldoc;
    }



    /**
    * For adding whole arrays to $this->xmldoc
    *
    * @param    array
    * @param    Object domNode
    * @access   private
    * @see      addArray()
    */

    function DoArray2Xml ($array, $parent) {

        while (list($key, $val) = each($array))
            {
                $tableInfo[$key]["table"]= $this->tagNameResult;
                $tableInfo[$key]["name"] = $key;
            }

        if ($this->user_tableInfo)
        {
            $tableInfo = $this->array_merge_clobber($tableInfo,$this->user_tableInfo);
        }
        foreach ($array as $key=>$value)
        {
            if (is_array($value) ) {
                if (is_int($key) )
                {
                    $valuenew = array_slice($value,0,1);
                    $keynew = array_keys($valuenew);
                    $keynew = $keynew[0];
                }
                else
                {

                    $valuenew = $value;
                    $keynew = $key;
                }

                $rec2 = $this->insertNewRow($parent, $valuenew, $keynew, &$tableInfo);
                $this->DoArray2xml($value,$rec2);
            }
            else {
                $this->insertNewElement($parent, $array, $key, &$tableInfo,&$subrow);
            }
        }

    }



    /**
    * This method sets the options for the class
    *  One can only set variables, which are defined at the top of
    *  of this class.
    *
    * @param    array   options to be passed to the class
    * @param    boolean   if the old suboptions should be deleted
    * @access   public
    * @see      $nested,$user_options,$user_tableInfo
    */

    function setOptions($options,$delete = False) {
    //set options
        if (is_array($options))
        {
            foreach ($options as $option => $value)
            {
               if (isset($this->{$option}))



본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

뜨거운 기사 태그

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

해결 방법: 조직에서 PIN 변경을 요구합니다. 해결 방법: 조직에서 PIN 변경을 요구합니다. Oct 04, 2023 pm 05:45 PM

해결 방법: 조직에서 PIN 변경을 요구합니다.

Windows 11에서 창 테두리 설정을 조정하는 방법: 색상 및 크기 변경 Windows 11에서 창 테두리 설정을 조정하는 방법: 색상 및 크기 변경 Sep 22, 2023 am 11:37 AM

Windows 11에서 창 테두리 설정을 조정하는 방법: 색상 및 크기 변경

Windows 11에서 작업 표시줄 축소판 미리 보기를 활성화 또는 비활성화하는 방법 Windows 11에서 작업 표시줄 축소판 미리 보기를 활성화 또는 비활성화하는 방법 Sep 15, 2023 pm 03:57 PM

Windows 11에서 작업 표시줄 축소판 미리 보기를 활성화 또는 비활성화하는 방법

Windows 11에서 제목 표시줄 색상을 변경하는 방법은 무엇입니까? Windows 11에서 제목 표시줄 색상을 변경하는 방법은 무엇입니까? Sep 14, 2023 pm 03:33 PM

Windows 11에서 제목 표시줄 색상을 변경하는 방법은 무엇입니까?

Windows 11/10 복구의 OOBELANGUAGE 오류 문제 Windows 11/10 복구의 OOBELANGUAGE 오류 문제 Jul 16, 2023 pm 03:29 PM

Windows 11/10 복구의 OOBELANGUAGE 오류 문제

Windows 11의 디스플레이 크기 조정 가이드 Windows 11의 디스플레이 크기 조정 가이드 Sep 19, 2023 pm 06:45 PM

Windows 11의 디스플레이 크기 조정 가이드

Windows 11에서 밝기를 조정하는 10가지 방법 Windows 11에서 밝기를 조정하는 10가지 방법 Dec 18, 2023 pm 02:21 PM

Windows 11에서 밝기를 조정하는 10가지 방법

Safari에서 iPhone의 개인 브라우징 인증을 끄는 방법은 무엇입니까? Safari에서 iPhone의 개인 브라우징 인증을 끄는 방법은 무엇입니까? Nov 29, 2023 pm 11:21 PM

Safari에서 iPhone의 개인 브라우징 인증을 끄는 방법은 무엇입니까?

See all articles