Hướng dẫn does php use xml? - php có sử dụng xml không?

Nhiều ví dụ trong tài liệu tham khảo này yêu cầu một chuỗi XML. Thay vì lặp lại chuỗi này trong mỗi ví dụ, chúng tôi đặt nó vào một tệp mà chúng tôi đưa vào mỗi ví dụ. Tệp bao gồm này được hiển thị trong phần ví dụ sau. Ngoài ra, bạn có thể tạo một tài liệu XML và đọc nó bằng SimplexML_Load_File ().simplexml_load_file().

Ví dụ #1 bao gồm tệp ví dụ.php với chuỗi XML

<?php
$xmlstr 
= <<<XML
<?xml version='1.0' standalone='yes'?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#211;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
XML;
?>

Tính đơn giản của SimplexML xuất hiện rõ ràng nhất khi một người trích xuất một chuỗi hoặc số từ tài liệu XML cơ bản.

Ví dụ #2 Nhận <plot>

<?php
include 'example.php';$movies = new SimpleXMLElement($xmlstr);

PHP solves all my web problems
0

PHP solves all my web problems
1

Ví dụ trên sẽ xuất ra:

   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.

Việc truy cập các phần tử trong tài liệu XML có chứa các ký tự không được phép theo quy ước đặt tên của PHP (ví dụ: dấu gạch nối) có thể được thực hiện bằng cách đóng gói tên phần tử trong niềng răng và apostrophe.

Ví dụ #3 Nhận

PHP solves all my web problems
2

<?php
include 'example.php';$movies = new SimpleXMLElement($xmlstr);

PHP solves all my web problems
0

PHP solves all my web problems
5

Ví dụ trên sẽ xuất ra:

PHP solves all my web problems

Việc truy cập các phần tử trong tài liệu XML có chứa các ký tự không được phép theo quy ước đặt tên của PHP (ví dụ: dấu gạch nối) có thể được thực hiện bằng cách đóng gói tên phần tử trong niềng răng và apostrophe.

Ví dụ #3 Nhận

PHP solves all my web problems
2

PHP solves all my web problems
6

Ví dụ trên sẽ xuất ra:

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr

Việc truy cập các phần tử trong tài liệu XML có chứa các ký tự không được phép theo quy ước đặt tên của PHP (ví dụ: dấu gạch nối) có thể được thực hiện bằng cách đóng gói tên phần tử trong niềng răng và apostrophe.:

Ví dụ #3 Nhận

PHP solves all my web problems
2

Ví dụ #4 Truy cập các yếu tố không duy nhất trong SimplexML

Khi nhiều trường hợp của một yếu tố tồn tại dưới dạng con của một yếu tố cha mẹ đơn lẻ, các kỹ thuật lặp thông thường được áp dụng.array.

PHP solves all my web problems
8

Ví dụ trên sẽ xuất ra:

Việc truy cập các phần tử trong tài liệu XML có chứa các ký tự không được phép theo quy ước đặt tên của PHP (ví dụ: dấu gạch nối) có thể được thực hiện bằng cách đóng gói tên phần tử trong niềng răng và apostrophe.

Ví dụ #3 Nhận

PHP solves all my web problems
2

<?php
include 'example.php';$movies = new SimpleXMLElement($xmlstr);

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
1

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
2

Ví dụ trên sẽ xuất ra:

My favorite movie.PHP: Behind the Parser

Việc truy cập các phần tử trong tài liệu XML có chứa các ký tự không được phép theo quy ước đặt tên của PHP (ví dụ: dấu gạch nối) có thể được thực hiện bằng cách đóng gói tên phần tử trong niềng răng và apostrophe.

Ví dụ #3 Nhận

PHP solves all my web problems
2

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
3

Ví dụ trên sẽ xuất ra:

Việc truy cập các phần tử trong tài liệu XML có chứa các ký tự không được phép theo quy ước đặt tên của PHP (ví dụ: dấu gạch nối) có thể được thực hiện bằng cách đóng gói tên phần tử trong niềng răng và apostrophe.

Ví dụ #3 Nhận

PHP solves all my web problems
2

<?php
include 'example.php';$movies = new SimpleXMLElement($xmlstr);

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
6

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
7

Ví dụ #4 Truy cập các yếu tố không duy nhất trong SimplexML

Ví dụ trên sẽ xuất ra:

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr

Việc truy cập các phần tử trong tài liệu XML có chứa các ký tự không được phép theo quy ước đặt tên của PHP (ví dụ: dấu gạch nối) có thể được thực hiện bằng cách đóng gói tên phần tử trong niềng răng và apostrophe.

Ví dụ #3 Nhận

PHP solves all my web problems
2

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
9

PHP solves all my web problems
0

My favorite movie.PHP: Behind the Parser
1

Ví dụ trên sẽ xuất ra:

<?xml version="1.0" standalone="yes"?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Miss Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#xD3;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>

Việc truy cập các phần tử trong tài liệu XML có chứa các ký tự không được phép theo quy ước đặt tên của PHP (ví dụ: dấu gạch nối) có thể được thực hiện bằng cách đóng gói tên phần tử trong niềng răng và apostrophe.

Ví dụ #3 Nhận

PHP solves all my web problems
2

My favorite movie.PHP: Behind the Parser
2

PHP solves all my web problems
0

My favorite movie.PHP: Behind the Parser
1

Ví dụ trên sẽ xuất ra:

<?xml version="1.0" standalone="yes"?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#xD3;r</actor>
   </character>
  <character><name>Mr. Parser</name><actor>John Doe</actor></character></characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 <rating type="mpaa">PG</rating></movie>
</movies>

Việc truy cập các phần tử trong tài liệu XML có chứa các ký tự không được phép theo quy ước đặt tên của PHP (ví dụ: dấu gạch nối) có thể được thực hiện bằng cách đóng gói tên phần tử trong niềng răng và apostrophe.

Ví dụ #3 Nhận

PHP solves all my web problems
2

My favorite movie.PHP: Behind the Parser
5

PHP solves all my web problems
0

My favorite movie.PHP: Behind the Parser
7

Ví dụ trên sẽ xuất ra:

Việc truy cập các phần tử trong tài liệu XML có chứa các ký tự không được phép theo quy ước đặt tên của PHP (ví dụ: dấu gạch nối) có thể được thực hiện bằng cách đóng gói tên phần tử trong niềng răng và apostrophe.

Ví dụ #3 Nhận

PHP solves all my web problems
2

My favorite movie.PHP: Behind the Parser
8

My favorite movie.PHP: Behind the Parser
9

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
0

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
1

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
2

Ví dụ #4 Truy cập các yếu tố không duy nhất trong SimplexML

Khi nhiều trường hợp của một yếu tố tồn tại dưới dạng con của một yếu tố cha mẹ đơn lẻ, các kỹ thuật lặp thông thường được áp dụng.

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
3

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
4

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
5

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
6

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
7

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
8

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
2

Ghi chú:

Thuộc tính (

PHP solves all my web problems
7 Trong ví dụ trước) không phải là mảng. Chúng là những đối tượng có thể truy cập và có thể truy cập.

<?xml version="1.0" standalone="yes"?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Miss Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#xD3;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
0

<?xml version="1.0" standalone="yes"?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Miss Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#xD3;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
1

<?xml version="1.0" standalone="yes"?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Miss Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#xD3;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
2

<?xml version="1.0" standalone="yes"?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Miss Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#xD3;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
3

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
2

Ví dụ #5 Sử dụng các thuộc tính

Cho đến nay, chúng tôi chỉ đề cập đến công việc đọc tên phần tử và giá trị của chúng. SimplexML cũng có thể truy cập các thuộc tính phần tử. Các thuộc tính truy cập của một phần tử giống như các phần tử của một mảng.

<?xml version="1.0" standalone="yes"?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Miss Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#xD3;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
5

<?xml version="1.0" standalone="yes"?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Miss Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#xD3;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
6

<?xml version="1.0" standalone="yes"?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Miss Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#xD3;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
7

<?xml version="1.0" standalone="yes"?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Miss Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#xD3;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
8

Ví dụ #6 so sánh các yếu tố và thuộc tính với văn bản

Để so sánh một phần tử hoặc thuộc tính với một chuỗi hoặc chuyển nó vào một hàm yêu cầu một chuỗi, bạn phải chuyển nó vào một chuỗi bằng cách sử dụng

PHP solves all my web problems
9. Nếu không, PHP coi phần tử là một đối tượng.

<?xml version="1.0" standalone="yes"?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Miss Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#xD3;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
9

<?xml version="1.0" standalone="yes"?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#xD3;r</actor>
   </character>
  <character><name>Mr. Parser</name><actor>John Doe</actor></character></characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 <rating type="mpaa">PG</rating></movie>
</movies>
0

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
2

Ví dụ #7 so sánh hai yếu tố

Để so sánh một phần tử hoặc thuộc tính với một chuỗi hoặc chuyển nó vào một hàm yêu cầu một chuỗi, bạn phải chuyển nó vào một chuỗi bằng cách sử dụng

PHP solves all my web problems
9. Nếu không, PHP coi phần tử là một đối tượng.

<?xml version="1.0" standalone="yes"?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#xD3;r</actor>
   </character>
  <character><name>Mr. Parser</name><actor>John Doe</actor></character></characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 <rating type="mpaa">PG</rating></movie>
</movies>
2

<?xml version="1.0" standalone="yes"?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#xD3;r</actor>
   </character>
  <character><name>Mr. Parser</name><actor>John Doe</actor></character></characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 <rating type="mpaa">PG</rating></movie>
</movies>
3

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
2

Ví dụ #7 so sánh hai yếu tố

Cho đến nay, chúng tôi chỉ đề cập đến công việc đọc tên phần tử và giá trị của chúng. SimplexML cũng có thể truy cập các thuộc tính phần tử. Các thuộc tính truy cập của một phần tử giống như các phần tử của một mảng.

<?xml version="1.0" standalone="yes"?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#xD3;r</actor>
   </character>
  <character><name>Mr. Parser</name><actor>John Doe</actor></character></characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 <rating type="mpaa">PG</rating></movie>
</movies>
5

<?xml version="1.0" standalone="yes"?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#xD3;r</actor>
   </character>
  <character><name>Mr. Parser</name><actor>John Doe</actor></character></characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 <rating type="mpaa">PG</rating></movie>
</movies>
6

<?xml version="1.0" standalone="yes"?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#xD3;r</actor>
   </character>
  <character><name>Mr. Parser</name><actor>John Doe</actor></character></characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 <rating type="mpaa">PG</rating></movie>
</movies>
7

<?xml version="1.0" standalone="yes"?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#xD3;r</actor>
   </character>
  <character><name>Mr. Parser</name><actor>John Doe</actor></character></characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 <rating type="mpaa">PG</rating></movie>
</movies>
8

<?xml version="1.0" standalone="yes"?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#xD3;r</actor>
   </character>
  <character><name>Mr. Parser</name><actor>John Doe</actor></character></characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 <rating type="mpaa">PG</rating></movie>
</movies>
9

<?php
$xmlstr 
= <<<XML
<?xml version='1.0' standalone='yes'?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#211;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
XML;
?>
0

<?php
$xmlstr 
= <<<XML
<?xml version='1.0' standalone='yes'?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#211;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
XML;
?>
1

<?php
$xmlstr 
= <<<XML
<?xml version='1.0' standalone='yes'?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#211;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
XML;
?>
2

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
2

Ví dụ #6 so sánh các yếu tố và thuộc tính với văn bản

Để so sánh một phần tử hoặc thuộc tính với một chuỗi hoặc chuyển nó vào một hàm yêu cầu một chuỗi, bạn phải chuyển nó vào một chuỗi bằng cách sử dụng

PHP solves all my web problems
9. Nếu không, PHP coi phần tử là một đối tượng.

<?php
$xmlstr 
= <<<XML
<?xml version='1.0' standalone='yes'?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#211;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
XML;
?>
4

<?php
$xmlstr 
= <<<XML
<?xml version='1.0' standalone='yes'?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#211;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
XML;
?>
5

<?php
$xmlstr 
= <<<XML
<?xml version='1.0' standalone='yes'?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#211;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
XML;
?>
6

<?php
$xmlstr 
= <<<XML
<?xml version='1.0' standalone='yes'?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#211;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
XML;
?>
7

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
2

Ví dụ #7 so sánh hai yếu tố

Cho đến nay, chúng tôi chỉ đề cập đến công việc đọc tên phần tử và giá trị của chúng. SimplexML cũng có thể truy cập các thuộc tính phần tử. Các thuộc tính truy cập của một phần tử giống như các phần tử của một mảng.

<?php
$xmlstr 
= <<<XML
<?xml version='1.0' standalone='yes'?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#211;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
XML;
?>
9

<plot>0

Ms. Coder played by Onlivia Actora
Mr. Coder played by El ActÓr
2

Ví dụ #6 so sánh các yếu tố và thuộc tính với văn bản

Để so sánh một phần tử hoặc thuộc tính với một chuỗi hoặc chuyển nó vào một hàm yêu cầu một chuỗi, bạn phải chuyển nó vào một chuỗi bằng cách sử dụng

PHP solves all my web problems
9. Nếu không, PHP coi phần tử là một đối tượng.

<plot>2

<plot>3

<plot>4

<plot>5