Java & XML 2nd Edition solutions to real world problems phần 4

Sử dụng phương pháp createElementNS () để tạo ra các yếu tố namespaced và tìm kiếm cho họ với getElementsByTagNameNSthay đổi kiến trúc của hệ thống hay ứng dụng của thư viện, hoặc thậm chí viết một dòng của Java! | Java XML 2nd Edition Serialize DOM tree DOMSerializer serializer new DOMSerializer doc xmlFile Print confirmation PrintWriter out text html HTML BODY Thank you for your submission. Your item has been processed. BODY HTML Using the createElementNS method to create namespaced elements and searching for them with getElementsByTagNameNS seems to be perfect. The createDocument method even has a handy place to insert the namespace URI for the root element. These elements are all put into the default namespace and everything looks fine. However there is a big problem here. Look at the output from running this servlet with no existing XML this is generated XML rather than modified XML xml version item id bourgOM name Bourgeois OM Guitar name description This is a i beautiful i b Sitka-topped b guitar with b Indian Rosewood b back and sides. Made by luthier a href http Dana Bourgeois a this OM has a b huge sound b . The guitar has i great action i a 1 3 4 nut and all i fossilized ivory i nut and saddle with i ebony i end pins. New condition this is a b great guitar b description item Does this look familiar It is the XML from earlier with no change The one thing that DOM does not do is add namespace declarations. Instead you ll need to manually add the xmlns attribute to your DOM tree otherwise when reading in the document the elements won t be placed into a namespace and you will have some problems. One small change takes care of this though Create new DOM tree DOMImplementation domImpl new DOMImplementationImpl doc docNS item null Element root xmlns docNS Now you ll get the namespace declaration that you were probably expecting to show up the first go round. You can compile these changes and try things out. You won t notice any difference changes are made just as they were before. However your documents .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã 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.