diff --git a/src/document.jl b/src/document.jl index eb6eea7..8cc69de 100644 --- a/src/document.jl +++ b/src/document.jl @@ -19,6 +19,11 @@ end # Document properties # ------------------- +Base.propertynames(x::Document) = ( + :version, :encoding, :root, :dtd, + fieldnames(typeof(x))... +) + @inline function Base.getproperty(doc::Document, name::Symbol) name == :version ? (hasversion(doc) ? version(doc) : nothing) : name == :encoding ? (hasencoding(doc) ? encoding(doc) : nothing) : diff --git a/src/node.jl b/src/node.jl index 963d698..8288f92 100644 --- a/src/node.jl +++ b/src/node.jl @@ -393,6 +393,11 @@ end # Node properties # --------------- +Base.propertynames(x::Node) = ( + :type, :name, :path, :content, :namespace, :document, :parentnode, :parentelement, :firstnode, :lastnode, :firstelement, :lastelement, :nextnode, :prevnode, :nextelement, :prevelement, + fieldnames(typeof(x))... +) + @inline function Base.getproperty(node::Node, name::Symbol) # node properties name == :type ? nodetype(node) : diff --git a/src/streamreader.jl b/src/streamreader.jl index e10ddc9..4a39724 100644 --- a/src/streamreader.jl +++ b/src/streamreader.jl @@ -18,6 +18,11 @@ mutable struct StreamReader end end +Base.propertynames(x::StreamReader) = ( + :type, :depth, :name, :content, :namespace, + fieldnames(typeof(x))... +) + @inline function Base.getproperty(reader::StreamReader, name::Symbol) name == :type ? nodetype(reader) : name == :depth ? nodedepth(reader) : diff --git a/test/runtests.jl b/test/runtests.jl index 5b99e39..188cfae 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -487,6 +487,7 @@ end @test nodetype(n) === EzXML.ELEMENT_NODE @test iselement(n) @test_throws ArgumentError document(n) + @test getproperty.(Ref(n), propertynames(n)) isa Tuple n = TextNode("some text") @test isa(n, EzXML.Node) @@ -550,6 +551,7 @@ end @test nodetype(doc.node) === EzXML.DOCUMENT_NODE @test !hasroot(doc) @test_throws ArgumentError root(doc) + @test getproperty.(Ref(doc), propertynames(doc)) isa Tuple doc = HTMLDocument() @test isa(doc, EzXML.Document)