
SimpleXMLElement 클래스의 getNamespaces 메서드는 XML 문서의 네임스페이스 정보를 반환하는 메서드입니다.
예를 들어, 다음과 같은 XML 문서가 있다고 가정해 보겠습니다.
#hostingforum.kr
xml
값
이 XML 문서에서 `getNamespaces` 메서드를 사용하여 네임스페이스 정보를 얻으려면 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
$xml = new SimpleXMLElement('값');
$namespaces = $xml->getNamespaces(true);
print_r($namespaces);
`getNamespaces` 메서드의 반환 값은 배열 형태의 데이터입니다.
#hostingforum.kr
php
Array
(
[xmlns] => http://example.com
[ns] => http://example.com/namespace
)
이 배열에는 XML 문서의 네임스페이스 정보가 포함되어 있습니다.
`getNamespaces` 메서드의 두 번째 인자는 `true`로 설정하면 네임스페이스 정보가 포함된 배열을 반환합니다.
`getNamespaces` 메서드의 두 번째 인자를 `false`로 설정하면 네임스페이스 정보가 포함되지 않은 배열을 반환합니다.
#hostingforum.kr
php
$xml = new SimpleXMLElement('값');
$namespaces = $xml->getNamespaces(false);
print_r($namespaces);
#hostingforum.kr
php
Array
(
[xmlns] =>
[ns] =>
)
2025-06-21 21:56