라이브러리

[PHP] DOMElement::getAttributeNodeNS - 속성 노드를 반환합니다.




DOMElement::getAttributeNodeNS 메서드


`DOMElement::getAttributeNodeNS` 메서드는 이름 공간이 지정된 특성 노드를 반환합니다. 이 메서드는 `DOMElement` 객체에 속한 특성 노드를 반환합니다.

# 메서드 시그니처


#hostingforum.kr
php

public DOMNamedNodeMap getAttributeNodeNS($namespaceURI, $localName)



# 매개 변수


* `$namespaceURI`: 이름 공간 URI
* `$localName`: 이름 공간이 지정된 특성 이름

# 반환 값


이 메서드는 이름 공간이 지정된 특성 노드를 반환합니다. 반환 값은 `DOMAttr` 객체입니다.

예제


#hostingforum.kr
php

// DOMDocument 객체 생성

$doc = new DOMDocument();

$doc->loadXML('30');



// DOMElement 객체 생성

$root = $doc->documentElement;

$person = $root->getElementsByTagName('person')->item(0);

$age = $person->getElementsByTagNameNS('http://example.com/ns', 'age')->item(0);



// getAttributeNodeNS 메서드 호출

$attr = $age->getAttributeNodeNS('http://example.com/ns', 'age');



// 반환 값 출력

echo $attr->nodeName . "
"; // ns:age

echo $attr->nodeValue . "
"; // 30

echo $attr->namespaceURI . "
"; // http://example.com/ns

echo $attr->localName . "
"; // age



참고


`getAttributeNodeNS` 메서드는 이름 공간이 지정된 특성 노드를 반환합니다. 이 메서드는 `getElementsByTagNameNS` 메서드와 함께 사용하여 이름 공간이 지정된 특성을 찾을 수 있습니다.

예제 (getElementsByTagNameNS 사용)


#hostingforum.kr
php

// DOMDocument 객체 생성

$doc = new DOMDocument();

$doc->loadXML('30');



// DOMElement 객체 생성

$root = $doc->documentElement;

$person = $root->getElementsByTagName('person')->item(0);

$ages = $person->getElementsByTagNameNS('http://example.com/ns', 'age');



// getAttributeNodeNS 메서드 호출

foreach ($ages as $age) {

    $attr = $age->getAttributeNodeNS('http://example.com/ns', 'age');

    echo $attr->nodeName . "
"; // ns:age

    echo $attr->nodeValue . "
"; // 30

    echo $attr->namespaceURI . "
"; // http://example.com/ns

    echo $attr->localName . "
"; // age

}



이 예제에서는 `getElementsByTagNameNS` 메서드를 사용하여 이름 공간이 지정된 특성을 찾은 후, `getAttributeNodeNS` 메서드를 사용하여 각 특성 노드를 반환합니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 614 페이지

검색

게시물 검색