2017-06-13 29 views
0

私はこのDOMElementを持っています。DOMElementから属性を取得する方法

私は2つの質問があります:オブジェクトの値は省略意味は何

1)?

2)どのようにしてこのDOMElementから属性を取得できますか?

object(DOMElement)#554 (18) { 
     ["tagName"]=> 
     string(5) "input" 
     ["schemaTypeInfo"]=> 
     NULL 
     ["nodeName"]=> 
     string(5) "input" 
     ["nodeValue"]=> 
     string(0) "" 
     ["nodeType"]=> 
     int(1) 
     ["parentNode"]=> 
     string(22) "(object value omitted)" 
     ["childNodes"]=> 
     string(22) "(object value omitted)" 
     ["firstChild"]=> 
     NULL 
     ["lastChild"]=> 
     NULL 
     ["previousSibling"]=> 
     string(22) "(object value omitted)" 
     ["nextSibling"]=> 
     string(22) "(object value omitted)" 
     ["attributes"]=> 
     string(22) "(object value omitted)" 
     ["ownerDocument"]=> 
     string(22) "(object value omitted)" 
     ["namespaceURI"]=> 
     NULL 
     ["prefix"]=> 
     string(0) "" 
     ["localName"]=> 
     string(5) "input" 
     ["baseURI"]=> 
     NULL 
     ["textContent"]=> 
     string(0) "" 
     } 

私はオブジェクトにアクセスするためにこのクラスを作成しました。これは、入力フィールドからtype属性を取得できるようにするためです。

<?php 

namespace App\Model; 

class Field 
{ 
    /** 
    * @var \DOMElement 
    */ 
    protected $node; 

    public function __construct($node){ 
     $this->node = $node; 
    } 

    public function getNode(){ 
     return $this->node; 
    } 

    public function getTagName(){ 

     foreach ($this->node as $value) { 
      return $value->tagName; 
     } 
    } 

    public function getAttribute(){ 


    } 
} 

答えて

1
  1. 私はあまりにも深く投棄および/またはオブジェクトグラフについての再帰的な情報を投棄を防止するために、(object value omitted)はいくつかの内部DOMまたはvar_dump()制限であると信じています。

  2. 次に、属性についての情報を得ることについて:

    • DOMElementすべての属性を取得するには、その親クラスDOMNodeで定義されたと返しDOMNamedNodeMapとさattributesプロパティを使用しますDOMAttrノード:

      // $this->node must be a DOMElement, otherwise $attributes will be NULL 
      $attributes = $this->node->attributes; 
      
      // then, to loop through all attributes: 
      foreach($attributes as $attribute) { 
          // do something with $attribute (which will be a DOMAttr instance) 
      } 
      // or, perhaps like so: 
      for($i = 0; $i < $attributes->length; $i++) { 
          $attribute = $attributes->item($i); 
          // do something with $attribute (which will be a DOMAttr instance) 
      } 
      
      // to get a single attribute from the map: 
      $typeAttribute = $attributes->getNamedItem('type'); 
      // (which will be a DOMAttr instance or NULL if it doesn't exist) 
      
    • ただ一つの属性を取得するには、012の名前DOMElementから、あなたが使用できます。

      • DOMElement::getAttributeNode()、そうのように、type属性を表しDOMAttrノードを取得するには:取得するには、

        $typeAttr = $this->node->getAttributeNode('type'); 
        // (which will be NULL if it doesn't exist) 
        

        または

      • DOMElement::getAttribute()属性typeの文字列値です。

        $typeAttrValue = $this->node->getAttribute('type'); 
        // (which will an empty string if it doesn't exist) 
        
関連する問題