
XMLReader::open 함수는 XML 파일을 열기 위해 사용하는 함수입니다. 파일 경로를 지정하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$xmlReader = new XMLReader();
$xmlReader->open('example.xml');
위 코드는 현재 디렉토리에서 'example.xml' 파일을 읽어옵니다. 파일 경로를 지정할 때, 절대 경로를 사용하거나 상대 경로를 사용할 수 있습니다. 상대 경로는 현재 디렉토리에서 시작하여 파일 경로를 지정합니다.
예를 들어, 현재 디렉토리에서 'example' 폴더에 'example.xml' 파일이 있다면, 다음과 같이 상대 경로를 사용할 수 있습니다.
#hostingforum.kr
php
$xmlReader->open('example/example.xml');
XMLReader::open 함수를 사용할 때, 에러가 발생하는 경우를 대비한 예외 처리 방법은 다음과 같습니다.
#hostingforum.kr
php
try {
$xmlReader = new XMLReader();
$xmlReader->open('example.xml');
} catch (Exception $e) {
echo 'XML 파일을 열 수 없습니다.';
}
위 코드는 XML 파일을 열 수 없는 경우 'XML 파일을 열 수 없습니다.' 메시지를 출력합니다.
2025-07-23 19:42