Пример #1
0
 /**
  * decodes the tags
  *
  * @return DOMDocument the decoded xml
  */
 public function decode()
 {
     $openTags = NULL;
     $node = NULL;
     $this->_codePage = $this->_dtd->getCurrentCodePage();
     while (!feof($this->_stream)) {
         $byte = $this->_getByte();
         switch ($byte) {
             case Syncroton_Wbxml_Abstract::END:
                 $node = $node->parentNode;
                 $openTags--;
                 break;
             case Syncroton_Wbxml_Abstract::OPAQUE:
                 $length = $this->_getMultibyteUInt();
                 if ($length > 0) {
                     $opaque = $this->_getOpaque($length);
                     try {
                         // let see if we can decode it. maybe the opaque data is wbxml encoded content
                         $opaqueDataStream = fopen("php://temp", 'r+');
                         fputs($opaqueDataStream, $opaque);
                         rewind($opaqueDataStream);
                         $opaqueContentDecoder = new Syncroton_Wbxml_Decoder($opaqueDataStream);
                         $dom = $opaqueContentDecoder->decode();
                         fclose($opaqueDataStream);
                         foreach ($dom->childNodes as $newNode) {
                             if ($newNode instanceof DOMElement) {
                                 $newNode = $this->_dom->importNode($newNode, true);
                                 $node->appendChild($newNode);
                             }
                         }
                     } catch (Exception $e) {
                         // if not, just treat it as a string
                         $node->appendChild($this->_dom->createTextNode($opaque));
                     }
                 }
                 break;
             case Syncroton_Wbxml_Abstract::STR_I:
                 $string = $this->_getTerminatedString();
                 $node->appendChild($this->_dom->createTextNode($string));
                 break;
             case Syncroton_Wbxml_Abstract::SWITCH_PAGE:
                 $page = $this->_getByte();
                 $this->_codePage = $this->_dtd->switchCodePage($page);
                 #echo "switched to codepage $page\n";
                 break;
             default:
                 $tagHasAttributes = ($byte & 0x80) != 0;
                 $tagHasContent = ($byte & 0x40) != 0;
                 // get rid of bit 7+8
                 $tagHexCode = $byte & 0x3f;
                 try {
                     $tag = $this->_codePage->getTag($tagHexCode);
                 } catch (Syncroton_Wbxml_Exception $swe) {
                     // tag can not be converted to ASCII name
                     $tag = sprintf('unknown tag 0x%x', $tagHexCode);
                 }
                 $nameSpace = $this->_codePage->getNameSpace();
                 $codePageName = $this->_codePage->getCodePageName();
                 #echo "Tag: $nameSpace:$tag\n";
                 if ($node === NULL) {
                     // create the domdocument
                     $node = $this->_createDomDocument($nameSpace, $tag);
                     $newNode = $node->documentElement;
                 } else {
                     if (!$this->_dom->isDefaultNamespace($nameSpace)) {
                         $this->_dom->documentElement->setAttribute('xmlns:' . $codePageName, $nameSpace);
                     }
                     $newNode = $node->appendChild($this->_dom->createElementNS('uri:' . $codePageName, $tag));
                 }
                 if ($tagHasAttributes) {
                     $attributes = $this->_getAttributes();
                 }
                 if ($tagHasContent == true) {
                     $node = $newNode;
                     $openTags++;
                 }
                 break;
         }
     }
     return $this->_dom;
 }
Пример #2
0
<?php

$doc = new DOMDocument();
$doc->load(dirname(__FILE__) . "/nsdoc.xml");
$root = $doc->documentElement;
$duri = $doc->lookupNamespaceURI("ns2") . "\n";
$euri = $root->lookupNamespaceURI("ns2") . "\n";
var_dump($duri == $euri);
$dpref = $doc->lookupPrefix("http://ns2") . "\n";
$epref = $root->lookupPrefix("http://ns2") . "\n";
var_dump($dpref == $epref);
$disdef = $doc->isDefaultNamespace("http://ns") . "\n";
$eisdef = $root->isDefaultNamespace("http://ns") . "\n";
var_dump($dpref === $epref);