You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-Bring convenience functions into your namespace with `using XML.NodeConstructors`:
63
+
-`using XML.NodeConstructors` will give you access to convenience functions (`document`, `cdata`, `element`, etc.) for creating `Node`s.
64
64
65
65
```julia
66
66
using XML.NodeConstructors
@@ -70,27 +70,37 @@ cdata("hello > < ' \" I have odd characters")
70
70
# Node CDATA <![CDATA[hello > < ' " I have odd characters]]>
71
71
```
72
72
73
-
### `XML.RowNode`
74
-
- A data structure that can used as a *Tables.jl* source. It is only lazy in how it accesses its children.
73
+
### `XML.LazyNode`
75
74
75
+
A lazy data structure that just keeps track of the position in the raw data (`Vector{UInt8}`) to read from.
76
76
77
-
### `XML.RawData`
78
-
- A super lazy data structure that holds the reference `Vector{UInt8}` data along with position/length to read from.
77
+
- 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.
79
78
79
+
```julia
80
+
doc =LazyNode(filename)
80
81
81
-
## Reading
82
+
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>
89
+
# ⋮
90
+
```
82
91
83
-
```julia
84
-
XML.RawData(filename)
85
92
86
-
RowNode(filename)
93
+
## Reading
87
94
95
+
```julia
96
+
# Reading from file:
88
97
Node(filename)
98
+
LazyNode(filename)
89
99
90
-
# Parsing:
91
-
parse(XML.RawData, str)
92
-
parse(RowNode, str)
100
+
# Parsing from string:
93
101
parse(Node, str)
102
+
parse(LazyNode, str)
103
+
94
104
```
95
105
96
106
## Writing
@@ -103,39 +113,22 @@ XML.write(io::IO, node) # write to stream
103
113
XML.write(node) # String
104
114
```
105
115
106
-
## Iteration
107
116
108
-
```julia
109
-
doc = XML.RowNode(filename)
110
-
111
-
foreach(println, doc)
112
-
# RowNode DECLARATION <?xml version="1.0">
113
-
# RowNode ELEMENT <catalog> (12 children)
114
-
# RowNode ELEMENT <book id="bk101"> (6 children)
115
-
# RowNode ELEMENT <author> (1 child)
116
-
# RowNode TEXT "Gambardella, Matthew"
117
-
# RowNode ELEMENT <title> (1 child)
118
-
# ⋮
119
117
120
-
# Use as Tables.jl source:
121
-
using DataFrames
122
118
123
-
DataFrame(doc)
124
-
```
119
+
## Performance
125
120
126
-
Note that you can also iterate through `XML.RawData`. However, *BEWARE* that this iterator
127
-
has some non-node elements (e.g. just the closing tag of an element).
121
+
- Comparing benchmarks (fairly) between packages is hard.
122
+
- The most fair comparison is between "XML.jl - Node Load" and `XMLDict.jl - read` in which XMLDict is 1.4x slower.
0 commit comments