XML in Rust, where to start?

Google doesn’t help a lot, or I don’t know where to look: I need a way to read xml files and compare them. The problem is not the comparing part, but the xml part. Could anyone please tell me a bit of a direction? I am happy to study and try myself, but I would like a good starting point

Go to lib.rs or crates.io and search for "XML".

2 Likes

937 results. Could you be a bit more specific?

Now search for "Read XML", and keep iterating

2 Likes

From the first two pages you can see that quick-xml and xml-rs are the most popular ones, so you could try one of them. quick-xml also seems to have serde support, which is nice if you already know beforehand the structure of your xml files.

2 Likes

I do know that, so I will start there. Thanks

Adding my 3 cents, this depends on:

  • Do you want to compare any 2 XMLs or do you want to compare 2 XMLs of a known structure?
  • Are those XMLs always conformant/valid?
  • Do they come from a trusted source?
1 Like

What exactly do you want to compare? Even with java, which has very advanced xml processing libraries, this may be something difficult.

Do you want to compare xml semantically? Then you need to check for the qualified name.

<a xmlns:xxx="bla"><xxx:bla>ble</xxx:bla></a> is the same thing as <a><bla xmlns="bla">ble</bla></a>

In java I perhaps would use a SAX processor and then see if the events are the same. Is there a SAX processor in Rust?

I would look for XML, DOM and SAX in the crates and see what you can find.

Never used it because I'm a NOOB in rust : https://crates.io/keywords/sax .

Which one to use? Probably the most downloaded? https://crates.io/crates/xml-rs

They come from a trusted source and their structure is known. I need to do a comparison of data over different years

What I want to do is find data with the same label, and see if the values are the same. So if the structure of the file changes, still those elements that remain the same can be compared

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.