diff --git a/Cargo.lock b/Cargo.lock index 68d1a542..87c3b224 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -377,12 +377,9 @@ checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "roxmltree" -version = "0.14.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "921904a62e410e37e215c40381b7117f830d9d89ba60ab5236170541dd25646b" -dependencies = [ - "xmlparser", -] +checksum = "3cd14fd5e3b777a7422cca79358c57a8f6e3a703d9ac187448d0daf220c2407f" [[package]] name = "strsim" @@ -625,12 +622,6 @@ version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fcb9cbac069e033553e8bb871be2fbdffcab578eb25bd0f7c508cedc6dcd75a" -[[package]] -name = "xmlparser" -version = "0.13.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" - [[package]] name = "xsd-macro-utils" version = "0.1.0" diff --git a/wsdl-parser-cli/Cargo.toml b/wsdl-parser-cli/Cargo.toml index 3fecd060..43c6bd91 100644 --- a/wsdl-parser-cli/Cargo.toml +++ b/wsdl-parser-cli/Cargo.toml @@ -17,6 +17,6 @@ path = "src/main.rs" [dependencies] anyhow = "1" clap = { version = "4", features = ["derive"] } -roxmltree = { version = "0.14", features = ["std"] } +roxmltree = { version = "0.19", features = ["std"] } wsdl-parser = { path = "../wsdl-parser" } xsd-parser = { path = "../xsd-parser" } diff --git a/wsdl-parser/Cargo.toml b/wsdl-parser/Cargo.toml index a83e9763..741befde 100644 --- a/wsdl-parser/Cargo.toml +++ b/wsdl-parser/Cargo.toml @@ -12,7 +12,7 @@ license = "MIT OR Apache-2.0" [dependencies] Inflector = "0.11" -roxmltree = "0.14" +roxmltree = "0.19" [dev-dependencies] syn = { version = "2", features = ["full", "extra-traits"] } diff --git a/wsdl-parser/src/parser/definitions.rs b/wsdl-parser/src/parser/definitions.rs index 1032dc9e..df04a627 100644 --- a/wsdl-parser/src/parser/definitions.rs +++ b/wsdl-parser/src/parser/definitions.rs @@ -48,7 +48,7 @@ pub struct Definitions<'a> { impl<'a> Definitions<'a> { pub fn target_namespace(&self) -> Option<&'a Namespace<'_>> { match self.node().attribute(attribute::TARGET_NAMESPACE) { - Some(tn) => self.node().namespaces().iter().find(|a| a.uri() == tn), + Some(tn) => self.node().namespaces().find(|a| a.uri() == tn), None => None, } } diff --git a/xsd-parser/Cargo.toml b/xsd-parser/Cargo.toml index 432b87b8..a13f5e60 100644 --- a/xsd-parser/Cargo.toml +++ b/xsd-parser/Cargo.toml @@ -12,7 +12,7 @@ license = "MIT OR Apache-2.0" [dependencies] Inflector = "0.11" -roxmltree = "0.14" +roxmltree = "0.19" [dev-dependencies] num-bigint = "0.4" diff --git a/xsd-parser/src/generator/default.rs b/xsd-parser/src/generator/default.rs index 81fa2d70..35bae277 100644 --- a/xsd-parser/src/generator/default.rs +++ b/xsd-parser/src/generator/default.rs @@ -156,8 +156,10 @@ mod test { ) .unwrap() .root_element() - .namespaces()[0] - .clone(), + .namespaces() + .next() + .cloned() + .unwrap(), ); assert_eq!(default_format_type("tt:Type", &ns), "Type"); assert_eq!(default_format_type("tt:TyName", &ns), "TyName"); diff --git a/xsd-parser/src/generator/utils.rs b/xsd-parser/src/generator/utils.rs index 98355ec6..ed947803 100644 --- a/xsd-parser/src/generator/utils.rs +++ b/xsd-parser/src/generator/utils.rs @@ -217,8 +217,10 @@ mod test { ) .unwrap() .root_element() - .namespaces()[0] - .clone(), + .namespaces() + .next() + .cloned() + .unwrap(), ); let match_type = |name| match_built_in_type(name, &xsd_ns); diff --git a/xsd-parser/src/parser/schema.rs b/xsd-parser/src/parser/schema.rs index 7f917468..36be5efb 100644 --- a/xsd-parser/src/parser/schema.rs +++ b/xsd-parser/src/parser/schema.rs @@ -8,15 +8,18 @@ use crate::parser::{ }; pub fn parse_schema<'input>(schema: &Node<'_, 'input>) -> RsFile<'input> { + let mut xsd_namespaces = schema + .namespaces() + .filter(|namespace| namespace.uri() == "http://www.w3.org/2001/XMLSchema"); + RsFile { name: "".into(), namespace: None, target_ns: target_namespace(schema).cloned(), - xsd_ns: schema - .namespaces() - .iter() - .rev() - .find(|a| a.uri() == "http://www.w3.org/2001/XMLSchema") + xsd_ns: xsd_namespaces + .clone() + .find(|namespace| namespace.name().is_some()) + .or_else(|| xsd_namespaces.next()) .cloned(), types: schema .children() @@ -39,6 +42,24 @@ pub fn parse_schema<'input>(schema: &Node<'_, 'input>) -> RsFile<'input> { mod test { use crate::parser::schema::parse_schema; + #[test] + fn test_single_xsd_ns() { + let doc = roxmltree::Document::parse( + r#" + + + "#, + ) + .unwrap(); + + let res = parse_schema(&doc.root_element()); + assert_eq!(res.xsd_ns.unwrap().name().unwrap(), "xs"); + } + #[test] fn test_multiple_xsd_ns() { let doc = roxmltree::Document::parse( @@ -56,6 +77,6 @@ mod test { .unwrap(); let res = parse_schema(&doc.root_element()); - assert_eq!(res.xsd_ns.unwrap().name().unwrap(), "xsd"); + assert_eq!(res.xsd_ns.unwrap().name().unwrap(), "xs"); } } diff --git a/xsd-parser/src/parser/utils.rs b/xsd-parser/src/parser/utils.rs index d96b8aca..4f35e01d 100644 --- a/xsd-parser/src/parser/utils.rs +++ b/xsd-parser/src/parser/utils.rs @@ -11,7 +11,7 @@ use crate::parser::{ pub fn target_namespace<'a, 'input>(node: &Node<'a, 'input>) -> Option<&'a Namespace<'input>> { match node.attribute(attribute::TARGET_NAMESPACE) { - Some(tn) => node.namespaces().iter().find(|a| a.uri() == tn), + Some(tn) => node.namespaces().find(|a| a.uri() == tn), None => None, } }