Easy XML DOM parser

Redefined classes

redef abstract class XMLAttrTag

dom :: dom $ XMLAttrTag

Any kind of XML tag with attributes
redef abstract class XMLEntity

dom :: dom $ XMLEntity

Any kind of XML Entity
redef class XMLStartTag

dom :: dom $ XMLStartTag

A (potentially) multi-line spanning XML Tag start

All class definitions

redef abstract class XMLAttrTag

dom :: dom $ XMLAttrTag

Any kind of XML tag with attributes
redef abstract class XMLEntity

dom :: dom $ XMLEntity

Any kind of XML Entity
redef class XMLStartTag

dom :: dom $ XMLStartTag

A (potentially) multi-line spanning XML Tag start
package_diagram dom::dom dom dom::parser parser dom::dom->dom::parser dom::xml_entities xml_entities dom::parser->dom::xml_entities ...dom::xml_entities ... ...dom::xml_entities->dom::xml_entities dom::checker checker dom::checker->dom::dom gamnit::bmfont bmfont gamnit::bmfont->dom::dom gamnit::texture_atlas_parser texture_atlas_parser gamnit::texture_atlas_parser->dom::dom nlp::stanford stanford nlp::stanford->dom::dom a_star-m a_star-m a_star-m->dom::checker a_star-m->gamnit::texture_atlas_parser a_star-m... ... a_star-m...->a_star-m gamnit::flat flat gamnit::flat->gamnit::bmfont gamnit::flat... ... gamnit::flat...->gamnit::flat nlp::nlp nlp nlp::nlp->nlp::stanford nlp::nlp... ... nlp::nlp...->nlp::nlp

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module array

core :: array

This module introduces the standard array structure.
module bitset

core :: bitset

Services to handle BitSet
module bytes

core :: bytes

Services for byte streams and arrays
module caching

serialization :: caching

Services for caching serialization engines
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.
module engine_tools

serialization :: engine_tools

Advanced services for serialization engines
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module exec

core :: exec

Invocation and management of operating system sub-processes.
module file

core :: file

File manipulations (create, read, write, etc.)
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module inspect

serialization :: inspect

Refine Serializable::inspect to show more useful information
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module kernel

core :: kernel

Most basic classes and methods.
module list

core :: list

This module handle double linked lists
module math

core :: math

Mathematical operations
module meta

meta :: meta

Simple user-defined meta-level to manipulate types of instances as object.
module native

core :: native

Native structures for text and bytes
module numeric

core :: numeric

Advanced services for Numeric types
module parser_base

parser_base :: parser_base

Simple base for hand-made parsers of all kinds
module protocol

core :: protocol

module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module re

core :: re

Regular expression support for all services based on Pattern
module ropes

core :: ropes

Tree-based representation of a String.
module serialization

serialization :: serialization

General serialization services
module serialization_core

serialization :: serialization_core

Abstract services to serialize Nit objects to different formats
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module stream

core :: stream

Input and output streams of characters
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O
module xml_entities

dom :: xml_entities

Basic blocks for DOM-XML representation

Parents

module parser

dom :: parser

XML DOM-parsing facilities

Children

module bmfont

gamnit :: bmfont

Parse Angel Code BMFont format and draw text
module checker

dom :: checker

Simple XML validity checker using the dom module
module stanford

nlp :: stanford

Natural Language Processor based on the StanfordNLP core.
module texture_atlas_parser

gamnit :: texture_atlas_parser

Tool to parse XML texture atlas and generated Nit code to access subtextures

Descendants

module a_star-m

a_star-m

module cardboard

gamnit :: cardboard

Update the orientation of world_camera at each frame using the head position given by android::cardboard
module depth

gamnit :: depth

Framework for 3D games in Nit
module flat

gamnit :: flat

Simple API for 2D games, built around Sprite and App::update
module more_materials

gamnit :: more_materials

Various material implementations
module more_models

gamnit :: more_models

Services to load models from the assets folder
module nlp

nlp :: nlp

Natural Language Processor based on the StanfordNLP core.
module nlp_index

nlp :: nlp_index

Example showing how to use a NLPFileIndex.
module selection

gamnit :: selection

Select Actor from a screen coordinate
module stereoscopic_view

gamnit :: stereoscopic_view

Refine EulerCamera and App::frame_core_draw to get a stereoscopic view
module virtual_gamepad

gamnit :: virtual_gamepad

Virtual gamepad mapped to keyboard keys for quick and dirty mobile support
module vr

gamnit :: vr

VR support for gamnit depth, for Android only
# Easy XML DOM parser
module dom

import parser

redef class XMLEntity

	# The `XMLTag` children with the `tag_name`
	#
	# ~~~
	# var code = """
	# <?xml version="1.0" encoding="us-ascii"?>
	# <animal>
	#     <cat/>
	#     <tiger>This is a white tiger!</tiger>
	#     <cat/>
	# </animal>"""
	#
	# var xml = code.to_xml
	# assert xml["animal"].length == 1
	# assert xml["animal"].first["cat"].length == 2
	# ~~~
	fun [](tag_name: String): Array[XMLTag]
	do
		var res = new Array[XMLTag]
		for child in children do
			if child isa XMLTag and child.tag_name == tag_name then
				res.add child
			end
		end
		return res
	end
end

redef class XMLStartTag

	# Content of this XML tag held within a `PCDATA` or `CDATA`
	#
	# ~~~
	# var code = """
	# <?xml version="1.0" encoding="us-ascii"?>
	# <animal>
	#     <cat/>
	#     <tiger>This is a white tiger!</tiger>
	#     <cat/>
	# </animal>"""
	#
	# var xml = code.to_xml
	# assert xml["animal"].first["tiger"].first.as(XMLStartTag).data == "This is a white tiger!"
	# ~~~
	fun data: nullable String
	do
		for child in children do
			if child isa PCDATA then return child.content
			if child isa CDATA then return child.content
		end
		return null
	end
end

redef class XMLAttrTag

	# Attributes as a map (ignoring malformed attributes)
	#
	# ~~~
	# var xml = """
	# <student first="Snow" last="Man"/>
	# """.to_xml
	#
	# var attributes = xml["student"].first.as(XMLAttrTag).attributes_to_map
	# assert attributes.join(", ", ":") == "first:Snow, last:Man"
	# ~~~
	fun attributes_to_map: Map[String, String]
	do
		var m = new Map[String, String]
		for a in attributes do
			if a isa XMLStringAttr then
				m[a.name] = a.value
			end
		end
		return m
	end
end
lib/dom/dom.nit:11,1--93,3