JuliaIO / EzXML.jl

XML/HTML handling tools for primates
MIT License
122 stars 36 forks source link
julia xml

EzXML.jl Logo

EzXML.jl - XML/HTML tools for primates

Docs Stable Docs Latest CI Status codecov.io

EzXML.jl is a package to handle XML/HTML documents for primates.

The main features are:

Installation

Install EzXML.jl as follows:

julia -e 'using Pkg; Pkg.add("EzXML")'

This package depends on libxml2, which will be automatically installed as an artifact via XML2_jll.jl if you use Julia 1.3 or later. Currently, Windows, Linux, macOS, and FreeBSD are now supported.

Version compatibility

EzXML.jl Julia
1.0 1.0 or later
1.1 1.3 or later
1.2 1.6 or later

Usage

# 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)  # or `doc.root`

# 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)  # or `species.content`
        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

Quick reference

See the reference page or docstrings for more details.

Types:

IO:

Accessors:

Constructors:

Queries:

Examples

Other XML/HTML packages in Julia