Skip to content

Commit f7e5fa9

Browse files
committed
rename things and make NodeType callable
1 parent 43cff52 commit f7e5fa9

File tree

5 files changed

+214
-251
lines changed

5 files changed

+214
-251
lines changed

README.md

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ using XML
3030

3131
filename = joinpath(dirname(pathof(XML)), "..", "test", "books.xml")
3232

33-
doc = Node(filename)
33+
doc = read(filename, Node)
3434

3535
children(doc)
36-
# 2-element Vector{Node}:
37-
# Node DECLARATION <?xml version="1.0"?>
38-
# Node ELEMENT <catalog> (12 children)
36+
# 2-Element Vector{Node}:
37+
# Node Declaration <?xml version="1.0"?>
38+
# Node Element <catalog> (12 children)
3939

4040
doc[end] # The root node
41-
# Node ELEMENT <catalog> (12 children)
41+
# Node Element <catalog> (12 children)
4242

4343
doc[end][2] # Second child of root
44-
# Node ELEMENT <book id="bk102"> (6 children)
44+
# Node Element <book id="bk102"> (6 children)
4545
```
4646

4747
## Node Types
@@ -60,14 +60,17 @@ push!(parent::Node, child::Node)
6060
parent[2] = child
6161
```
6262

63-
- `using XML.NodeConstructors` will give you access to convenience functions (`document`, `cdata`, `element`, etc.) for creating `Node`s.
63+
- **XML** defines `(::NodeType)(args...; kw...)` for more convenient syntax in creating `Node`s, e.g.:
6464

6565
```julia
66-
using XML.NodeConstructors
67-
# cdata, comment, declaration, document, dtd, element, processing_instruction, text
68-
69-
cdata("hello > < ' \" I have odd characters")
70-
# Node CDATA <![CDATA[hello > < ' " I have odd characters]]>
66+
CData(value)
67+
Comment(value)
68+
Declaration(; attributes...)
69+
Document(children...)
70+
DTD(; attributes...)
71+
Element(tag, children...; attributes...)
72+
ProcessingInstruction(; attributes...)
73+
Text(value)
7174
```
7275

7376
### `XML.LazyNode`
@@ -77,15 +80,15 @@ A lazy data structure that just keeps track of the position in the raw data (`Ve
7780
- Iteration in depth first search (DFS) order. This is the natural order in which you would visit XML nodes by reading an XML document from top to bottom.
7881

7982
```julia
80-
doc = LazyNode(filename)
83+
doc = read(filename, LazyNode)
8184

8285
foreach(println, doc)
83-
# LazyNode DECLARATION <?xml version="1.0"?>
84-
# LazyNode ELEMENT <catalog>
85-
# LazyNode ELEMENT <book id="bk101">
86-
# LazyNode ELEMENT <author>
87-
# LazyNode TEXT "Gambardella, Matthew"
88-
# LazyNode ELEMENT <title>
86+
# LazyNode Declaration <?xml version="1.0"?>
87+
# LazyNode Element <catalog>
88+
# LazyNode Element <book id="bk101">
89+
# LazyNode Element <author>
90+
# LazyNode Text "Gambardella, Matthew"
91+
# LazyNode Element <title>
8992
#
9093
```
9194

@@ -94,8 +97,8 @@ foreach(println, doc)
9497

9598
```julia
9699
# Reading from file:
97-
Node(filename)
98-
LazyNode(filename)
100+
read(filename, Node)
101+
read(filename, LazyNode)
99102

100103
# Parsing from string:
101104
parse(Node, str)

0 commit comments

Comments
 (0)