1. Trang chủ
  2. » Công Nghệ Thông Tin

Sams XPath Navigating XML With XPath 1 0 And 2 0 Kick Start Dec 2003 ISBN 0672324113

6 29 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 6
Dung lượng 271,45 KB

Nội dung

Creating Comparison Expressions Comparison expressions return the result of comparing two values XPath 2.0 actually supports four kinds of comparison expressions: value comparisons, general comparisons, node comparisons, and order comparisons We'll take a look at them all here, starting with value and general comparisons These two types of comparisons have been added so that XPath 2.0 can support comparisons with both single values and with sequences Value Comparisons You use the value comparison operators when you're working with atomic values Here they are: eq Equals ne Not equals lt Less than le Less than or equal to gt Greater than ge Greater than or equal to These operators give you a result of true or false Here's an examplesay that $temperature holds the value 68; in that case, this expression would evaluate to true: $temperature lt 72 This comparison is true only if $planet has a single child element and its value is "Venus": $planet/name eq "Venus" SHOP TALK: DATA TYPES AND TYPE ERRORS Here's something to noteif $planet/name evaluates to more than one name node, or $planet/name evaluates to one name node, which contains more than one validated string, a type error is raised It's important to realize that type errors are the most significant difference between XPath 1.0 and XPath 2.0 If the XPath processor determines that there's been a type error, even a relatively innocent one like this one, a type error occurs Strong typing like this is at the very heart of XPath 2.0 In my work with XPath 2.0, that is by far the biggest difference between XPath 1.0 and 2.0 However, how type errors are handled is up to the implementation So far, all that usually happens is that XPath or XQuery processors simply stop and display an error message That's not what you want to have happen when someone else is using your XPath or XQuery expressions, of course, so be careful I always spend some time trying to think of type problems that could break XPath expressions, and try to make sure that such problems won't arise Until XPath processors come up with some way of handling type errors as recoverable errors, the strong data typing in XPath 2.0 is something I recommend you pay special attention to General Comparisons You can use general comparisons on sequences (including singleton sequences) Here are the general comparisons: = Equals != Not equals < Less than Greater than >= Greater than or equal to ESCAPING RULES As in XPath 1.0, when you use XPath expressions inside an XML document, the XML escaping rules for special characters should be followed For example, "

Ngày đăng: 26/03/2019, 17:13