Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate name and content in favor of nodename and nodecontent #26

Merged
merged 5 commits into from
Sep 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ for genus in eachelement(primates)
println("- ", genus_name)
for species in eachelement(genus)
# Get the content within an element.
species_name = content(species)
species_name = nodecontent(species)
println(" └ ", species["name"], " (", species_name, ")")
end
end
println()

# Find texts using XPath query.
for species_name in content.(find(primates, "//species/text()"))
for species_name in nodecontent.(find(primates, "//species/text()"))
println("- ", species_name)
end
```
Expand All @@ -79,7 +79,7 @@ IO:
* To stream: `print(io, doc)`

Accessors:
* Node information: `nodetype(node)`, `nodepath(node)`, `name(node)`, `content(node)`
* Node information: `nodetype(node)`, `nodepath(node)`, `nodename(node)`, `nodecontent(node)`, `setnodename!(node, name)`, `setnodecontent!(node, content)`
* Document: `root(doc)`, `dtd(doc)`, `hasroot(doc)`, `hasdtd(doc)`, `setroot!(doc, element_node)`, `setdtd!(doc, dtd_node)`
* Attributes: `node[name]`, `node[name] = value`, `haskey(node, name)`, `delete!(node, name)`
* Node predicate:
Expand Down
18 changes: 9 additions & 9 deletions docs/src/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ EzXML.Node(<ELEMENT_NODE@0x00007fff3d109ef0>)
julia> nodetype(primates) # The node is an element node.
ELEMENT_NODE

julia> name(primates) # `name` returns the tag name of an element.
julia> nodename(primates) # `nodename` returns the tag name of an element.
"primates"

julia> haselement(primates) # Check if a node has one or more elements.
Expand All @@ -114,7 +114,7 @@ julia> genus = elements(primates) # `elements` returns all child elements.
EzXML.Node(<ELEMENT_NODE@0x00007fff3cff0000>)
EzXML.Node(<ELEMENT_NODE@0x00007fff3cfbdf00>)

julia> name.(genus) # Broadcasting syntax (dot function) works.
julia> nodename.(genus) # Broadcasting syntax (dot function) works.
2-element Array{String,1}:
"genus"
"genus"
Expand Down Expand Up @@ -268,7 +268,7 @@ julia> print(doc)
<?xml version="1.0" encoding="UTF-8"?>
<root><child/></root>

julia> setcontent!(c, "some content")
julia> setnodecontent!(c, "some content")
EzXML.Node(<ELEMENT_NODE@0x00007fe4b57de820>)

julia> print(doc)
Expand Down Expand Up @@ -301,7 +301,7 @@ shell> cat out.xml

An alternative way is using the `addelement!(<parent>, <child>, [<content>])`
function, which is a shorthand of a sequence operations: `ElementNode(<child name>)`,
`link!(<parent>, <child>)`, and optional `setcontent!(<child>, <content>)`. This
`link!(<parent>, <child>)`, and optional `setnodecontent!(<child>, <content>)`. This
is often handier in typical use:
```jlcon
julia> doc = XMLDocument()
Expand Down Expand Up @@ -460,7 +460,7 @@ false
julia> nodetype(reader)
READER_ELEMENT

julia> name(reader)
julia> nodename(reader)
"graphml"

julia> done(reader) # Read the 2nd node.
Expand All @@ -469,7 +469,7 @@ false
julia> nodetype(reader)
READER_SIGNIFICANT_WHITESPACE

julia> name(reader)
julia> nodename(reader)
"#text"

julia> done(reader) # Read the 3rd node.
Expand All @@ -478,7 +478,7 @@ false
julia> nodetype(reader)
READER_ELEMENT

julia> name(reader)
julia> ndoename(reader)
"graph"

julia> reader["edgedefault"]
Expand All @@ -489,8 +489,8 @@ julia> reader["edgedefault"]
Unlike DOM interfaces, methods are applied to a reader object. This is because
the streaming reader does not construct a DOM tree while reading and hence we
have no access to actual nodes of an XML document. Methods like `nodetype`,
`name`, `content`, `namespace` and `getindex` are overloaded for the reader
type.
`nodename`, `nodecontent`, `namespace` and `getindex` are overloaded for the
reader type.

An important thing to be noted is that while the value of `nodetype` for the XML
reader returns the current node type, the domain is slightly different from that
Expand Down
12 changes: 6 additions & 6 deletions docs/src/references.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ Node accessors
```@docs
nodetype(::Node)
nodepath(::Node)
name(::Node)
content(::Node)
nodename(::Node)
nodecontent(::Node)
namespace(::Node)
namespaces(::Node)
iselement(::Node)
Expand All @@ -96,8 +96,8 @@ Node modifiers
--------------

```@docs
setname!(::Node, ::AbstractString)
setcontent!(::Node, ::AbstractString)
setnodename!(::Node, ::AbstractString)
setnodecontent!(::Node, ::AbstractString)
```

DOM tree accessors
Expand Down Expand Up @@ -200,7 +200,7 @@ Streaming reader
depth(::StreamReader)
expandtree(::StreamReader)
nodetype(::StreamReader)
name(::StreamReader)
content(::StreamReader)
nodename(::StreamReader)
nodecontent(::StreamReader)
namespace(::StreamReader)
```
2 changes: 1 addition & 1 deletion example/listlinks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ doc = readhtml(ARGS[1])
links = find(doc, "//a[@href and normalize-space(text()) != '']")
width = ndigits(length(links))
for (i, link) in enumerate(links)
println(lpad(i, width), ": ", strip(content(link)), " -- ", link["href"])
println(lpad(i, width), ": ", strip(nodecontent(link)), " -- ", link["href"])
end
4 changes: 2 additions & 2 deletions example/primates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ for genus in eachelement(primates)
println("- ", genus_name)
for species in eachelement(genus)
# Get the content within an element.
species_name = content(species)
species_name = nodecontent(species)
println(" └ ", species["name"], " (", species_name, ")")
end
end
println()

# Find texts using XPath query.
for species_name in content.(find(primates, "//species/text()"))
for species_name in nodecontent.(find(primates, "//species/text()"))
println("- ", species_name)
end
14 changes: 10 additions & 4 deletions src/EzXML.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ export
isdtd,
hasdocument,
document,
name,
setname!,
content,
setcontent!,
nodename,
setnodename!,
nodecontent,
setnodecontent!,
systemID,
externalID,
eachnode,
Expand Down Expand Up @@ -108,6 +108,12 @@ include("buffer.jl")
include("xpath.jl")
include("streamreader.jl")

# Deprecation
@deprecate name nodename
@deprecate setname! setnodename!
@deprecate content nodecontent
@deprecate setcontent! setnodecontent!

function __init__()
init_error_handler()
end
Expand Down
16 changes: 8 additions & 8 deletions src/node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -991,11 +991,11 @@ function document(node::Node)
end

"""
name(node::Node)
nodename(node::Node)

Return the node name of `node`.
"""
function name(node::Node)
function nodename(node::Node)
node_str = unsafe_load(node.ptr)
if node_str.name == C_NULL
throw(ArgumentError("no node name"))
Expand All @@ -1004,11 +1004,11 @@ function name(node::Node)
end

"""
setname!(node::Node, name::AbstractString)
setnodename!(node::Node, name::AbstractString)

Set the name of `node`.
"""
function setname!(node::Node, name::AbstractString)
function setnodename!(node::Node, name::AbstractString)
ccall(
(:xmlNodeSetName, libxml2),
Void,
Expand All @@ -1018,11 +1018,11 @@ function setname!(node::Node, name::AbstractString)
end

"""
content(node::Node)
nodecontent(node::Node)

Return the node content of `node`.
"""
function content(node::Node)
function nodecontent(node::Node)
str_ptr = @check ccall(
(:xmlNodeGetContent, libxml2),
Cstring,
Expand All @@ -1034,11 +1034,11 @@ function content(node::Node)
end

"""
setcontent!(node::Node, content::AbstractString)
setnodecontent!(node::Node, content::AbstractString)

Replace the content of `node`.
"""
function setcontent!(node::Node, content::AbstractString)
function setnodecontent!(node::Node, content::AbstractString)
ccall(
(:xmlNodeSetContentLen, libxml2),
Void,
Expand Down
8 changes: 4 additions & 4 deletions src/streamreader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ function nodetype(reader::StreamReader)
end

"""
name(reader::StreamReader)
nodename(reader::StreamReader)

Return the name of the current node of `reader`.
"""
function name(reader::StreamReader)
function nodename(reader::StreamReader)
name_ptr = ccall(
(:xmlTextReaderConstName, libxml2),
Cstring,
Expand All @@ -233,11 +233,11 @@ function name(reader::StreamReader)
end

"""
content(reader::StreamReader)
nodecontent(reader::StreamReader)

Return the content of the current node of `reader`.
"""
function content(reader::StreamReader)
function nodecontent(reader::StreamReader)
content_ptr = ccall(
(:xmlTextReaderReadString, libxml2),
Cstring,
Expand Down
Loading