From ad6c3dd258994feeed281d3c8277ef2a488e3a0c Mon Sep 17 00:00:00 2001 From: aminya Date: Sun, 9 Feb 2020 22:42:34 -0600 Subject: [PATCH 1/7] Remove node.ptr from show Fix tests --- src/node.jl | 2 +- test/runtests.jl | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/node.jl b/src/node.jl index fe74d3a..96396db 100644 --- a/src/node.jl +++ b/src/node.jl @@ -303,7 +303,7 @@ function Base.show(io::IO, node::Node) else desc = repr(ntype) end - @printf(io, "%s(<%s@%p>)", prefix, desc, node.ptr) + @printf(io, "%s(<%s>)", prefix, desc) end function Base.print(io::IO, node::Node) diff --git a/test/runtests.jl b/test/runtests.jl index 9cf40a5..3b8621d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1301,10 +1301,10 @@ end @testset "Misc" begin @testset "show" begin doc = parsexml("""""") - @test occursin(r"^EzXML.Node\(\)$", repr(doc.node)) - @test occursin(r"^EzXML.Node\(\)$", repr(root(doc))) - @test occursin(r"^EzXML.Node\(\)$", repr(attributes(root(doc))[1])) - @test occursin(r"^EzXML.Document\(EzXML.Node\(\)\)$", repr(doc)) + @test occursin(r"^EzXML.Node\(\)$", repr(doc.node)) + @test occursin(r"^EzXML.Node\(\)$", repr(root(doc))) + @test occursin(r"^EzXML.Node\(\)$", repr(attributes(root(doc))[1])) + @test occursin(r"^EzXML.Document\(EzXML.Node\(\)\)$", repr(doc)) sample2 = joinpath(dirname(@__FILE__), "sample2.xml") reader = open(EzXML.StreamReader, sample2) From 8778e299770403f530be4c8c8c1f226f205bf782 Mon Sep 17 00:00:00 2001 From: aminya Date: Sat, 29 Feb 2020 17:18:19 -0600 Subject: [PATCH 2/7] Remove Ptr from StreamReader --- src/streamreader.jl | 3 ++- test/runtests.jl | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/streamreader.jl b/src/streamreader.jl index 448c6f7..b982f44 100644 --- a/src/streamreader.jl +++ b/src/streamreader.jl @@ -29,7 +29,8 @@ end function Base.show(io::IO, reader::StreamReader) prefix = isdefined(Main, :StreamReader) ? "StreamReader" : "EzXML.StreamReader" - @printf(io, "%s(<%s@%p>)", prefix, repr(nodetype(reader)), reader.ptr) + nodetype_reader = repr(nodetype(reader)) + @printf(io, "%s(<%s>)", prefix, nodetype_reader) end # Reader type (enum xmlReaderTypes). diff --git a/test/runtests.jl b/test/runtests.jl index 3b8621d..a21f29f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1308,7 +1308,7 @@ end sample2 = joinpath(dirname(@__FILE__), "sample2.xml") reader = open(EzXML.StreamReader, sample2) - @test occursin(r"^EzXML.StreamReader\(<[A-Z_]+@0x[a-f0-9]+>\)$", repr(reader)) + @test occursin(r"^EzXML.StreamReader\(<[A-Z_]+>\)$", repr(reader)) close(reader) end From 8fa3af163a3ecd45f73244bf50ab5d1deb64d399 Mon Sep 17 00:00:00 2001 From: aminya Date: Sat, 29 Feb 2020 17:18:59 -0600 Subject: [PATCH 3/7] using print instead of @printf --- Project.toml | 1 - src/EzXML.jl | 1 - src/node.jl | 2 +- src/streamreader.jl | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index eda9ef7..85a22e5 100644 --- a/Project.toml +++ b/Project.toml @@ -4,7 +4,6 @@ authors = ["Kenta Sato "] version = "1.1.0" [deps] -Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" XML2_jll = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a" [compat] diff --git a/src/EzXML.jl b/src/EzXML.jl index 08c226c..53dbf76 100644 --- a/src/EzXML.jl +++ b/src/EzXML.jl @@ -102,7 +102,6 @@ export hasnodeattributes, nodeattributes -using Printf: @printf using XML2_jll: libxml2 include("error.jl") diff --git a/src/node.jl b/src/node.jl index 96396db..0250fb5 100644 --- a/src/node.jl +++ b/src/node.jl @@ -303,7 +303,7 @@ function Base.show(io::IO, node::Node) else desc = repr(ntype) end - @printf(io, "%s(<%s>)", prefix, desc) + print(io, "$(prefix)(<$(desc)>)") end function Base.print(io::IO, node::Node) diff --git a/src/streamreader.jl b/src/streamreader.jl index b982f44..73b22df 100644 --- a/src/streamreader.jl +++ b/src/streamreader.jl @@ -30,7 +30,7 @@ end function Base.show(io::IO, reader::StreamReader) prefix = isdefined(Main, :StreamReader) ? "StreamReader" : "EzXML.StreamReader" nodetype_reader = repr(nodetype(reader)) - @printf(io, "%s(<%s>)", prefix, nodetype_reader) + print(io, "$(prefix)(<$(nodetype_reader)>)") end # Reader type (enum xmlReaderTypes). From bcdcf5778f9d0d8a88d2c87a083b060882be64cb Mon Sep 17 00:00:00 2001 From: aminya Date: Sat, 29 Feb 2020 17:19:54 -0600 Subject: [PATCH 4/7] Faster show --- src/node.jl | 2 +- src/streamreader.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node.jl b/src/node.jl index 0250fb5..1fc5e5e 100644 --- a/src/node.jl +++ b/src/node.jl @@ -296,7 +296,7 @@ function ismanaged(node::Node) end function Base.show(io::IO, node::Node) - prefix = isdefined(Main, :Node) ? "Node" : "EzXML.Node" + prefix = "EzXML.Node" ntype = nodetype(node) if ntype ∈ (ELEMENT_NODE, ATTRIBUTE_NODE) && hasnodename(node) desc = string(repr(ntype), '[', nodename(node), ']') diff --git a/src/streamreader.jl b/src/streamreader.jl index 73b22df..71a28f5 100644 --- a/src/streamreader.jl +++ b/src/streamreader.jl @@ -28,7 +28,7 @@ end end function Base.show(io::IO, reader::StreamReader) - prefix = isdefined(Main, :StreamReader) ? "StreamReader" : "EzXML.StreamReader" + prefix = "EzXML.StreamReader" nodetype_reader = repr(nodetype(reader)) print(io, "$(prefix)(<$(nodetype_reader)>)") end From eefee4e8b50aa85de13a79c2272ed9bd49ed499e Mon Sep 17 00:00:00 2001 From: aminya Date: Sat, 29 Feb 2020 20:37:45 -0600 Subject: [PATCH 5/7] No EzXML prefix in showing --- src/node.jl | 2 +- src/streamreader.jl | 2 +- test/runtests.jl | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/node.jl b/src/node.jl index 1fc5e5e..0a09c81 100644 --- a/src/node.jl +++ b/src/node.jl @@ -296,7 +296,7 @@ function ismanaged(node::Node) end function Base.show(io::IO, node::Node) - prefix = "EzXML.Node" + prefix = "Node" ntype = nodetype(node) if ntype ∈ (ELEMENT_NODE, ATTRIBUTE_NODE) && hasnodename(node) desc = string(repr(ntype), '[', nodename(node), ']') diff --git a/src/streamreader.jl b/src/streamreader.jl index 71a28f5..4c2b6cd 100644 --- a/src/streamreader.jl +++ b/src/streamreader.jl @@ -28,7 +28,7 @@ end end function Base.show(io::IO, reader::StreamReader) - prefix = "EzXML.StreamReader" + prefix = "StreamReader" nodetype_reader = repr(nodetype(reader)) print(io, "$(prefix)(<$(nodetype_reader)>)") end diff --git a/test/runtests.jl b/test/runtests.jl index a21f29f..bcce7f2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1301,14 +1301,14 @@ end @testset "Misc" begin @testset "show" begin doc = parsexml("""""") - @test occursin(r"^EzXML.Node\(\)$", repr(doc.node)) - @test occursin(r"^EzXML.Node\(\)$", repr(root(doc))) - @test occursin(r"^EzXML.Node\(\)$", repr(attributes(root(doc))[1])) - @test occursin(r"^EzXML.Document\(EzXML.Node\(\)\)$", repr(doc)) + @test occursin(r"^Node\(\)$", repr(doc.node)) + @test occursin(r"^Node\(\)$", repr(root(doc))) + @test occursin(r"^Node\(\)$", repr(attributes(root(doc))[1])) + @test occursin(r"^EzXML.Document\(Node\(\)\)$", repr(doc)) sample2 = joinpath(dirname(@__FILE__), "sample2.xml") reader = open(EzXML.StreamReader, sample2) - @test occursin(r"^EzXML.StreamReader\(<[A-Z_]+>\)$", repr(reader)) + @test occursin(r"^StreamReader\(<[A-Z_]+>\)$", repr(reader)) close(reader) end From 746aee00e53a45a50c6382f13818046127f07ff0 Mon Sep 17 00:00:00 2001 From: aminya Date: Sat, 29 Feb 2020 21:12:59 -0600 Subject: [PATCH 6/7] show for Document --- src/document.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/document.jl b/src/document.jl index eb6eea7..619dd7b 100644 --- a/src/document.jl +++ b/src/document.jl @@ -51,6 +51,12 @@ function HTMLDocument(uri=nothing, externalID=nothing) return Document(node.ptr) end +function Base.show(io::IO, doc::Document) + prefix = "EzXML.Document" + node = repr(doc.node) + print(io, "$(prefix)($node)") +end + function Base.print(io::IO, doc::Document) print(io, doc.node) end From 9af7c7e66aef93a51e6a9fff977231ead9016ec2 Mon Sep 17 00:00:00 2001 From: aminya Date: Sat, 29 Feb 2020 21:13:06 -0600 Subject: [PATCH 7/7] Update docs --- docs/src/manual.md | 92 +++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/docs/src/manual.md b/docs/src/manual.md index 2390b72..5863ef3 100644 --- a/docs/src/manual.md +++ b/docs/src/manual.md @@ -49,13 +49,13 @@ constructor: julia> using EzXML julia> doc = XMLDocument() -EzXML.Document(EzXML.Node()) +EzXML.Document(Node()) julia> typeof(doc) EzXML.Document julia> doc.node -EzXML.Node() +Node() julia> typeof(doc.node) EzXML.Node @@ -72,20 +72,20 @@ The text just before the `@` sign shows the node type (in this example, Let's add a root node to the document and a text node to the root node: ```jldoctest doc julia> elm = ElementNode("root") # create an element node -EzXML.Node() +Node() julia> setroot!(doc, elm) -EzXML.Node() +Node() julia> print(doc) julia> txt = TextNode("some text") # create a text node -EzXML.Node() +Node() julia> link!(elm, txt) -EzXML.Node() +Node() julia> print(doc) @@ -111,7 +111,7 @@ The value of a property will be `nothing` when there is no corresponding value. ```jldoctest julia> elm = ElementNode("element") -EzXML.Node() +Node() julia> println(elm) @@ -144,7 +144,7 @@ julia> println(elm) some text julia> txt = TextNode(" text ") -EzXML.Node() +Node() julia> println(txt) text @@ -167,19 +167,19 @@ julia> txt.content child element to an existing node: ```jldoctest julia> user = ElementNode("User") -EzXML.Node() +Node() julia> println(user) julia> addelement!(user, "id", "167492") -EzXML.Node() +Node() julia> println(user) 167492 julia> addelement!(user, "name", "Kumiko Oumae") -EzXML.Node() +Node() julia> println(user) 167492Kumiko Oumae @@ -218,12 +218,12 @@ Likewise, `parsexml()` parses an XML string or a byte array in memory and builds a document object: ```jldoctest dom julia> doc = readxml("primates.xml") -EzXML.Document(EzXML.Node()) +EzXML.Document(Node()) julia> data = String(read("primates.xml")); julia> doc = parsexml(data) -EzXML.Document(EzXML.Node()) +EzXML.Document(Node()) ``` @@ -231,12 +231,12 @@ Before traversing a document we need to get the root of the document tree. The `.root` property returns the root element (if any) of a document: ```jldoctest dom julia> primates = doc.root # get the root element -EzXML.Node() +Node() julia> genus = elements(primates) # `elements` returns all child elements. 2-element Array{EzXML.Node,1}: - EzXML.Node() - EzXML.Node() + Node() + Node() julia> genus[1].type, genus[1].name (ELEMENT_NODE, "genus") @@ -294,19 +294,19 @@ indicate a node type the property (function) is interested in. For example, but `.firstelement` always returns the first element node (if any): ```jldoctest dom julia> primates.firstnode -EzXML.Node() +Node() julia> primates.firstelement -EzXML.Node() +Node() julia> primates.firstelement == genus[1] true julia> primates.lastnode -EzXML.Node() +Node() julia> primates.lastelement -EzXML.Node() +Node() julia> primates.lastelement === genus[2] true @@ -350,30 +350,30 @@ and elements, respectively: julia> for node in eachnode(primates) @show node end -node = EzXML.Node() -node = EzXML.Node() -node = EzXML.Node() -node = EzXML.Node() -node = EzXML.Node() +node = Node() +node = Node() +node = Node() +node = Node() +node = Node() julia> for node in eachelement(primates) @show node end -node = EzXML.Node() -node = EzXML.Node() +node = Node() +node = Node() julia> nodes(primates) 5-element Array{EzXML.Node,1}: - EzXML.Node() - EzXML.Node() - EzXML.Node() - EzXML.Node() - EzXML.Node() + Node() + Node() + Node() + Node() + Node() julia> elements(primates) 2-element Array{EzXML.Node,1}: - EzXML.Node() - EzXML.Node() + Node() + Node() ``` @@ -388,22 +388,22 @@ The `findall`, `findfirst` and `findlast` functions are overloaded for XPath query and return a vector of selected nodes: ```jldoctest xpath julia> primates = readxml("primates.xml") -EzXML.Document(EzXML.Node()) +EzXML.Document(Node()) julia> findall("/primates", primates) # Find the "primates" element just under the document 1-element Array{EzXML.Node,1}: - EzXML.Node() + Node() julia> findall("//genus", primates) 2-element Array{EzXML.Node,1}: - EzXML.Node() - EzXML.Node() + Node() + Node() julia> findfirst("//genus", primates) -EzXML.Node() +Node() julia> findlast("//genus", primates) -EzXML.Node() +Node() julia> println(findfirst("//genus", primates)) @@ -416,7 +416,7 @@ If you would like to change the starting node of a query, you can pass the node as the second argument of `find*`: ```jldoctest xpath julia> genus = findfirst("//genus", primates) -EzXML.Node() +Node() julia> println(genus) @@ -445,7 +445,7 @@ julia> doc = parsexml(""" """) -EzXML.Document(EzXML.Node()) +EzXML.Document(Node()) julia> findall("/parent/child", doc.root) # nothing will be found 0-element Array{EzXML.Node,1} @@ -459,7 +459,7 @@ julia> ns = namespace(doc.root) # get the namespace julia> findall("/x:parent/x:child", doc.root, ["x"=>ns]) # specify its prefix as "x" 1-element Array{EzXML.Node,1}: - EzXML.Node() + Node() ``` @@ -495,7 +495,7 @@ thing you needs to do is to create an `EzXML.StreamReader` object using the `open` function: ```jldoctest stream julia> reader = open(EzXML.StreamReader, "undirected.graphml") -EzXML.StreamReader() +StreamReader() ``` @@ -548,7 +548,7 @@ available from the file. When you finished reading data, you need to call `close(reader)` to release allocated resources: ```jldoctest julia> reader = open(EzXML.StreamReader, "undirected.graphml") -EzXML.StreamReader() +StreamReader() julia> while (item = iterate(reader)) != nothing @show reader.type, reader.name @@ -599,7 +599,7 @@ iterable via the `for` loop. Therefore, you can iterate over all components without explicitly calling `iterate` as follows: ```jldoctest julia> reader = open(EzXML.StreamReader, "undirected.graphml") -EzXML.StreamReader() +StreamReader() julia> for typ in reader @show typ, reader.name