|
19 | 19 | //! use sxd_document::parser; |
20 | 20 | //! use sxd_xpath::{evaluate_xpath, Value}; |
21 | 21 | //! |
22 | | -//! fn main() { |
23 | | -//! let package = parser::parse("<root>hello</root>").expect("failed to parse XML"); |
24 | | -//! let document = package.as_document(); |
| 22 | +//! let package = parser::parse("<root>hello</root>").expect("failed to parse XML"); |
| 23 | +//! let document = package.as_document(); |
25 | 24 | //! |
26 | | -//! let value = evaluate_xpath(&document, "/root").expect("XPath evaluation failed"); |
| 25 | +//! let value = evaluate_xpath(&document, "/root").expect("XPath evaluation failed"); |
27 | 26 | //! |
28 | | -//! assert_eq!("hello", value.string()); |
29 | | -//! } |
| 27 | +//! assert_eq!("hello", value.string()); |
30 | 28 | //! ``` |
31 | 29 | //! |
32 | 30 | //! Evaluating an XPath returns a [`Value`][], representing the |
|
45 | 43 | //! use sxd_document::parser; |
46 | 44 | //! use sxd_xpath::{Factory, Context, Value}; |
47 | 45 | //! |
48 | | -//! fn main() { |
49 | | -//! let package = parser::parse("<root>hello</root>") |
50 | | -//! .expect("failed to parse XML"); |
51 | | -//! let document = package.as_document(); |
| 46 | +//! let package = parser::parse("<root>hello</root>") |
| 47 | +//! .expect("failed to parse XML"); |
| 48 | +//! let document = package.as_document(); |
52 | 49 | //! |
53 | | -//! let factory = Factory::new(); |
54 | | -//! let xpath = factory.build("/root").expect("Could not compile XPath"); |
| 50 | +//! let factory = Factory::new(); |
| 51 | +//! let xpath = factory.build("/root").expect("Could not compile XPath"); |
55 | 52 | //! |
56 | | -//! let context = Context::new(); |
| 53 | +//! let context = Context::new(); |
57 | 54 | //! |
58 | | -//! let value = xpath.evaluate(&context, document.root()) |
59 | | -//! .expect("XPath evaluation failed"); |
| 55 | +//! let value = xpath.evaluate(&context, document.root()) |
| 56 | +//! .expect("XPath evaluation failed"); |
60 | 57 | //! |
61 | | -//! assert_eq!("hello", value.string()); |
62 | | -//! } |
| 58 | +//! assert_eq!("hello", value.string()); |
63 | 59 | //! ``` |
64 | 60 | //! |
65 | 61 | //! See [`Context`][] for details on how to customize the |
|
83 | 79 | //! defined prefixes, some XPath behavior may be confusing: |
84 | 80 | //! |
85 | 81 | //! 1. The `name` method will not include a prefix, even if the |
86 | | -//! element or attribute has a namespace. |
| 82 | +//! element or attribute has a namespace. |
87 | 83 | //! 2. The `namespace` axis will not include namespaces without |
88 | | -//! prefixes. |
| 84 | +//! prefixes. |
89 | 85 | //! |
90 | 86 | //! #### Document order |
91 | 87 | //! |
92 | 88 | //! If you have programmatically created XML but not attached the |
93 | 89 | //! nodes to the document, some XPath behavior may be confusing: |
94 | 90 | //! |
95 | 91 | //! 1. These nodes have no [*document order*]. If you create a |
96 | | -//! variable containing these nodes and apply a predicate to them, |
97 | | -//! these nodes will appear after any nodes that are present in the |
98 | | -//! document, but the relative order of the nodes is undefined. |
| 92 | +//! variable containing these nodes and apply a predicate to them, |
| 93 | +//! these nodes will appear after any nodes that are present in the |
| 94 | +//! document, but the relative order of the nodes is undefined. |
99 | 95 | //! |
100 | 96 | //! [*document order*]: https://www.w3.org/TR/xpath/#dt-document-order |
101 | 97 |
|
| 98 | +// Ignoring these as our MSRV predates the suggestions |
| 99 | +#![allow( |
| 100 | + clippy::legacy_numeric_constants, |
| 101 | + clippy::match_like_matches_macro, |
| 102 | + clippy::option_as_ref_deref, |
| 103 | +)] |
| 104 | + |
102 | 105 | use snafu::{ResultExt, Snafu}; |
103 | 106 | use std::borrow::ToOwned; |
104 | 107 | use std::string; |
@@ -442,12 +445,10 @@ pub enum Error { |
442 | 445 | /// use sxd_document::parser; |
443 | 446 | /// use sxd_xpath::{evaluate_xpath, Value}; |
444 | 447 | /// |
445 | | -/// fn main() { |
446 | | -/// let package = parser::parse("<root><a>1</a><b>2</b></root>").expect("failed to parse the XML"); |
447 | | -/// let document = package.as_document(); |
| 448 | +/// let package = parser::parse("<root><a>1</a><b>2</b></root>").expect("failed to parse the XML"); |
| 449 | +/// let document = package.as_document(); |
448 | 450 | /// |
449 | | -/// assert_eq!(Ok(Value::Number(3.0)), evaluate_xpath(&document, "/*/a + /*/b")); |
450 | | -/// } |
| 451 | +/// assert_eq!(Ok(Value::Number(3.0)), evaluate_xpath(&document, "/*/a + /*/b")); |
451 | 452 | /// ``` |
452 | 453 | pub fn evaluate_xpath<'d>(document: &'d Document<'d>, xpath: &str) -> Result<Value<'d>, Error> { |
453 | 454 | let factory = Factory::new(); |
|
0 commit comments