라이브러리

[PHP] XMLReader::open - 구문 분석할 XML을 포함하는 URI를 설정합니다.




XMLReader::open 메서드 소개


XMLReader::open 메서드는 XMLReader 클래스의 메서드 중 하나로, XML 문서를 읽기 시작하도록 합니다. 이 메서드는 XML 문서의 경로를 지정하여 XMLReader 객체를 초기화합니다.

XMLReader::open 메서드 사용법


XMLReader::open 메서드는 다음과 같은 형식으로 사용할 수 있습니다.

#hostingforum.kr
php

XMLReader::open($xmlFilePath, $encoding = 'UTF-8', $options = LIBXML_NOERROR);



- `$xmlFilePath`: XML 문서의 경로를 지정합니다.
- `$encoding`: XML 문서의 인코딩을 지정합니다. 기본값은 'UTF-8'입니다.
- `$options`: XML 문서의 옵션을 지정합니다. 기본값은 LIBXML_NOERROR입니다.

예제: XMLReader::open 메서드 사용하기


다음 예제에서는 XMLReader::open 메서드를 사용하여 XML 문서를 읽어들이는 방법을 보여줍니다.

#hostingforum.kr
php

// XML 문서의 경로를 지정합니다.

$xmlFilePath = 'example.xml';



// XMLReader 객체를 초기화합니다.

$xmlReader = new XMLReader();



// XMLReader::open 메서드를 사용하여 XML 문서를 읽기 시작합니다.

$xmlReader->open($xmlFilePath);



// XML 문서를 읽어들이는 반복문을 사용합니다.

while ($xmlReader->read()) {

    // XML 문서의 현재 노드를 확인합니다.

    echo $xmlReader->name . ' : ' . $xmlReader->value . "
";

}



// XMLReader::close 메서드를 사용하여 XMLReader 객체를 닫습니다.

$xmlReader->close();



예제 XML 문서 (`example.xml`):

#hostingforum.kr
xml



    

        John Doe

        30

    

    

        Jane Doe

        25

    





예제 결과


#hostingforum.kr


root : 

person : 

name : John Doe

age : 30

person : 

name : Jane Doe

age : 25



참고


- XMLReader 클래스는 XML 문서를 읽기 위한 클래스입니다.
- XMLReader::open 메서드는 XML 문서를 읽기 시작하도록 합니다.
- XMLReader::close 메서드는 XMLReader 객체를 닫습니다.
- XMLReader::read 메서드는 XML 문서의 현재 노드를 확인합니다.
- XMLReader::name 메서드는 XML 문서의 현재 노드 이름을 확인합니다.
- XMLReader::value 메서드는 XML 문서의 현재 노드 값을 확인합니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 8,985건 / 36 페이지

검색

게시물 검색