
DOMElement::getAttributeNS 메소드는 이름 공간을 사용하여 XML 문서의 특성을 가져올 수 있는 방법입니다.
이름 공간이 없을 때는 getAttributeNS 메소드는 null을 반환합니다.
예를 들어, 다음 XML 문서가 있다고 가정해 보겠습니다.
#hostingforum.kr
xml
이 경우, 다음 코드는 null을 반환합니다.
#hostingforum.kr
php
$doc = new DOMDocument();
$doc->loadXML('');
$element = $doc->getElementsByTagName('element')->item(0);
echo $element->getAttributeNS(null, 'attr'); // null
이름 공간이 있을 때는 getAttributeNS 메소드는 이름 공간을 사용하여 특성을 가져올 수 있습니다.
예를 들어, 다음 XML 문서가 있다고 가정해 보겠습니다.
#hostingforum.kr
xml
이 경우, 다음 코드는 "value"를 반환합니다.
#hostingforum.kr
php
$doc = new DOMDocument();
$doc->loadXML('');
$element = $doc->getElementsByTagName('element')->item(0);
echo $element->getAttributeNS('http://example.com/namespace', 'attr'); // value
이름 공간이 없을 때는 getAttributeNS 메소드는 null을 반환합니다. 이름 공간이 있을 때는 getAttributeNS 메소드는 이름 공간을 사용하여 특성을 가져올 수 있습니다.
2025-06-22 07:44