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
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
PHP solves all my web problems0 PHP solves all my web problems1 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 problems0 PHP solves all my web problems5 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 problems2 PHP solves all my web problems6 Ví dụ trên sẽ xuất ra: Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr
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 problems8 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 problems2
Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr1 Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr2 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 problems2 Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr3 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 problems2
Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr6 Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr7 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 problems2 Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr9 PHP solves all my web problems0 My favorite movie.PHP: Behind the Parser1 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Ó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 problems2 My favorite movie.PHP: Behind the Parser2 PHP solves all my web problems0 My favorite movie.PHP: Behind the Parser1 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Ó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 problems2 My favorite movie.PHP: Behind the Parser5 PHP solves all my web problems0 My favorite movie.PHP: Behind the Parser7 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 My favorite movie.PHP: Behind the Parser8 My favorite movie.PHP: Behind the Parser9 Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr0 Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr1 Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr2 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Ór3 Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr4 Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr5 Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr6 Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr7 Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr8 Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr2 Ghi chú: ¶ Thuộc tính ( <?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Ó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Ó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Ó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Ó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Ór2 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Ó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Ó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Ó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Ó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 <?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Ó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Ó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Ór2 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 <?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Ó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Ó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Ór2 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Ó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Ó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Ó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Ó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Ó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
Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr2 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
Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr2 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.
Ms. Coder played by Onlivia Actora Mr. Coder played by El ActÓr2 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
<plot> 5 |