Home
EzXML.jl is a package for handling XML and HTML documents. The APIs are simple and consistent, and provide a range of functionalities including:
- Reading and writing XML/HTML documents.
- Traversing XML/HTML trees with DOM interfaces.
- Searching elements using XPath.
- Proper namespace handling.
- Capturing error messages.
- Automatic memory management.
- Document validation.
- Streaming parsing for large XML files.
Here is an example of parsing and traversing an XML document:
# Load the package.
using EzXML
# Parse an XML string
# (use `readxml(<filename>)` to read a document from a file).
doc = parsexml("""
<primates>
<genus name="Homo">
<species name="sapiens">Human</species>
</genus>
<genus name="Pan">
<species name="paniscus">Bonobo</species>
<species name="troglodytes">Chimpanzee</species>
</genus>
</primates>
""")
# Get the root element from `doc`.
primates = root(doc)
# Iterate over child elements.
for genus in eachelement(primates)
# Get an attribute value by name.
genus_name = genus["name"]
println("- ", genus_name)
for species in eachelement(genus)
# Get the content within an element.
species_name = nodecontent(species)
println(" └ ", species["name"], " (", species_name, ")")
end
end
println()
# Find texts using XPath query.
for species_name in nodecontent.(findall("//species/text()", primates))
println("- ", species_name)
end
If you are new to this package, read the manual page first. It provides a general guide to the package. The reference page offers a full documentation for each function, and the developer notes page explains about the internal design for developers.