라이브러리

[PHP] XMLWriter::startElement - 시작 요소 태그 생성




XMLWriter::startElement

`XMLWriter::startElement` 메서드는 XML 문서에서 요소를 시작하는 데 사용됩니다. 이 메서드는 XML 문서의 구조를 정의하고, 요소의 이름과 속성을 지정합니다.

사용법


`XMLWriter::startElement` 메서드는 다음과 같은 형식으로 사용됩니다.

#hostingforum.kr
php

XMLWriter::startElement(string $name, array $attributes = array())



* `$name`: 요소의 이름입니다.
* `$attributes`: 요소의 속성입니다. 속성은 이름과 값으로 구성됩니다.

예제


다음 예제에서는 `XMLWriter::startElement` 메서드를 사용하여 XML 문서를 생성하는 방법을 보여줍니다.

#hostingforum.kr
php

$xml = new XMLWriter();

$xml->openURI('php://memory');

$xml->startDocument('1.0', 'UTF-8');

$xml->startElement('root');

$xml->writeAttribute('version', '1.0');

$xml->startElement('name');

$xml->writeAttribute('lang', 'ko');

$xml->text('John Doe');

$xml->endElement(); // name

$xml->endElement(); // root

$xml->flush();

$xml->rewind();

echo $xml->output();



이 예제에서는 `XMLWriter` 클래스를 사용하여 XML 문서를 생성합니다. `startDocument` 메서드를 사용하여 XML 문서의 버전과 인코딩을 지정합니다. `startElement` 메서드를 사용하여 요소를 시작하고, `writeAttribute` 메서드를 사용하여 속성을 지정합니다. `text` 메서드를 사용하여 요소의 내용을 지정합니다. `endElement` 메서드를 사용하여 요소를 종료합니다. `flush` 메서드를 사용하여 XML 문서를 생성하고, `rewind` 메서드를 사용하여 XML 문서를 다시 읽습니다. `output` 메서드를 사용하여 XML 문서를 출력합니다.

결과


XML 문서의 결과는 다음과 같습니다.

#hostingforum.kr
xml

<?xml version="1.0" encoding="UTF-8"?>



    John Doe





참고


* `XMLWriter` 클래스는 PHP 5.1.0부터 사용할 수 있습니다.
* `XMLWriter::startElement` 메서드는 XML 문서의 구조를 정의하고, 요소의 이름과 속성을 지정합니다.
* `XMLWriter::writeAttribute` 메서드는 요소의 속성을 지정합니다.
* `XMLWriter::text` 메서드는 요소의 내용을 지정합니다.
* `XMLWriter::endElement` 메서드는 요소를 종료합니다.
* `XMLWriter::flush` 메서드는 XML 문서를 생성합니다.
* `XMLWriter::rewind` 메서드는 XML 문서를 다시 읽습니다.
* `XMLWriter::output` 메서드는 XML 문서를 출력합니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

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

검색

게시물 검색