- Generally match
MSXML2.DOMDocument
- Utilize
Dictionary
andCollection
to add no new classes - Xml = ConvertToXml(ParseXml(Xml))
- prolog:
<? ... ?>
- doctype:
<!doctype ... [...]>
- documentElement: Root element
- Element:
#document (Element)
prolog: (Element)
doctype: (Element)
documentElement: (Element)
nodeName: "#document"
childNodes:
- (prolog)
- (doctype)
- (documentElement)
attributes: (empty)
text: ""
xml: "..."
- nodeName
String
- childNodes
Collection
- attributes
Dictionary
- text
String
- xml
String
<messages name="Tim"><message id="1">A</message><message id="2">B</message></messages>
^ ^ ^ ^ ^ ^ ^ ^ ^ ^
a b c d e f g h i j
parseElement
- a:
<
, nodeName = "messages" - b:
non->
, attribute, key = "name" - c:
=
, value = "Tim" - d:
>
, close opening tag, check for childNodes/text/void next - e:
< + non-/
, opening tag, childNodes + parseElement - f:
non-<
, text = "A" - g:
</
, closing tag, find > and exit parseElement - h:
< + non-/
, another opening tag, childNodes + parseElement - i:
</
, closing tag, find > and exit parseElement - j:
</
, closing tag, find > and exit original parseElement
Look for space -> attributes
Look for > -> end of opening
If void element, look for immediate </...> or <
Otherwise:
Look for immediate < -> childNodes -> parseElement
Look for ... -> text
Look for immediate </ -> close element
TODO Handle comments
parseAttribute -> Array(Key, Value)
createElement(nodeName, childNodes, attributes, text, xml) -> Dictionary
Helper for loading values into Dictionary
- Parse prolog into Element
- Parse doctype into Element
- Use
parseElement
starting after doctype for documentElement - Create #document element and add prolog, doctype, and documentElement