라이브러리
[PHP] DOMElement::hasAttributeNS - 속성이 존재하는지 확인합니다.
DOMElement::hasAttributeNS
DOMElement::hasAttributeNS는 DOMElement 객체의 특정 이름 공간에 속한 특성 존재 여부를 확인하는 메소드입니다.
# 사용법
#hostingforum.kr
php
DOMElement::hasAttributeNS(string $namespaceURI, string $localName)
- `$namespaceURI`: 이름 공간의 URI
- `$localName`: 특성의 로컬 이름
# 예제
#hostingforum.kr
php
// XML 문서를 생성
$xml = new DOMDocument();
$xml->loadXML('');
// DOMElement 객체를 생성
$element = $xml->getElementsByTagName('ns:element')->item(0);
// 특성 존재 여부를 확인
echo var_export($element->hasAttributeNS('http://example.com/ns', 'attr'), true) . "
"; // true
echo var_export($element->hasAttributeNS('http://example.com/ns', 'non-existent-attr'), true) . "
"; // false
# 설명
- `$xml->loadXML`를 사용하여 XML 문서를 생성합니다.
- `$xml->getElementsByTagName`를 사용하여 특정 이름 공간에 속한 요소를 찾습니다.
- `hasAttributeNS` 메소드를 사용하여 특성 존재 여부를 확인합니다.
# 주의사항
- 이름 공간의 URI와 로컬 이름을 정확하게 지정해야 합니다.
- 특성 이름은 대소문자를 구분하지 않습니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.