tailieunhanh - PHP 5 Recipes A Problem-Solution Approach PHẦN 9

Ví dụ tiếp theo cho thấy làm thế nào để loại bỏ việc tạo ra và phụ thêm các thuộc tính và chỉ đơn giản là chỉ định các thuộc tính cần thiết đến các yếu tố mà bạn cần ví dụ này, bạn tạo ra và thêm các thuộc tính của cây để các phần tử bảng và giao cho một số giá trị. Sản lượng sau đó sẽ như thế này | 522 14-4 CREATING AND SETTING ATTRIBUTES How It Works In this example you create and append the tree attributes to the table element and assign them some values. The output will then look like this html body table width 100 height 50 border 1 tr td value1 td td value2 td tr table body html Because attributes are automatically created you can reduce this example a bit without impacting the result. The next example shows how to remove the creation and appending of attributes and simply assign the needed attributes to the elements where you need them. The Code php Example root new DomDocument iso-8859-1 html root- createElement html body root- createElement body table root- createElement table table- setAttribute width 100 table- setAttribute height 50 table- setAttribute border 1 row root- createElement tr cell root- createElement td value1 row- appendChild cell cell root- createElement td value2 row- appendChild cell table- appendChild row body- appendChild table html- appendChild body root- appendChild html echo root- saveHTML The DomElement object also includes methods to check for the existence of an attribute remove an attribute and get the value of an attribute. The methods are called hasAttribute removeAttribute and getAttribute . These functions all take the attribute name as the only parameter. 14-5 PARSING XML 523 14-5. Parsing XML So far we have been discussing generating HTML and XML documents but you can also use the DOM extension to load and parse both HTML and XML documents. Unlike XML documents HTML documents do not have to be well formatted browsers can render HTML documents with missing end tags so it is likely to see errors or warnings when these documents are loaded. The DomDocument class includes methods to parse string values as HTML or XML and methods to load the content directly from a file or as a stream. The next example does not make much sense but it demonstrates how to read the HTML content directly from a Uniform Resource

TÀI LIỆU MỚI ĐĂNG
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.