Cyclone 3DR Script
from Technodigit, part of Hexagon. Copyright 1997-2024.
Loading...
Searching...
No Matches
SXmlReader Class Reference

Allow to read xml files. More...

Public Types

enum  ErrorEnum { NoError = 0 , NotWellFormedError = 3 , PrematureEndOfDocumentError = 4 , UnexpectedElementError = 1 }
 The type of the current error. More...
 
enum  TokenTypeEnum {
  NoToken = 0 , Invalid = 1 , StartDocument = 2 , EndDocument = 3 ,
  StartElement = 4 , EndElement = 5 , Characters = 6 , Comment = 7 ,
  DTD = 8 , EntityReference = 9 , ProcessingInstruction = 10
}
 The token type. More...
 

Public Member Functions

boolean AtEnd ()
 Return if the end of the file has been reached (all the file has been read or an error has occurred) More...
 
Array< Object > Attributes ()
 Get the attributes of a StartElement. More...
 
string DocumentEncoding ()
 If the TokenType() is StartDocument, this function returns the encoding string as specified in the XML declaration. Otherwise an empty string is returned. More...
 
string DocumentVersion ()
 If the TokenType() is StartDocument, this function returns the version string as specified in the XML declaration. Otherwise an empty string is returned. More...
 
ErrorEnum Error ()
 Return the type of the current error, or NoError if no error occurred. More...
 
boolean HasError ()
 Return if an error has occurred. More...
 
boolean IsStandaloneDocument ()
 Return if this document has been declared standalone in the XML declaration. If no XML declaration has been parsed, this function returns false. More...
 
boolean IsWhitespace ()
 Return if the reader reports characters that only consist of white-space. More...
 
number LineNumber ()
 Return the current line number, starting with 1. More...
 
string Name ()
 Return the local name of a StartElement, EndElement, or an EntityReference. More...
 
string NamespaceUri ()
 Return the namespaceUri of a StartElement or EndElement. More...
 
TokenTypeEnum ReadNext ()
 Read the next token and return its type. More...
 
 SetFile (SFile file)
 Set the current file to device. Setting the device resets reader. More...
 
 SkipCurrentElement ()
 Read until the end of the current element, skipping any child nodes. This function is useful for skipping unknown elements. The current element is the element matching the most recently parsed start element of which a matching end element has not yet been reached. When the parser has reached the end element, the current element becomes the parent element. More...
 
 SXmlReader ()
 Default constructor to instantiate a XmlReader. More...
 
string Text ()
 Return the text of Characters, Comment, DTD, or EntityReference. More...
 
string TokenString ()
 Return the reader's current token as string. More...
 
TokenTypeEnum TokenType ()
 Return the type of the current token. More...
 
string toString ()
 Get the type of the variable. More...
 

Static Public Member Functions

static SXmlReader New ()
 Default constructor to instantiate a XmlReader. More...
 

Detailed Description

Allow to read xml files.

Sample on how to use this class:

var fileName = "...";
var xmlReader = SXmlReader.New();
var file = SFile.New(fileName);
// Open XML file to read
if ( !file.Open(SFile.ReadOnly) )
throw new Error( 'Failed to read file.' );
xmlReader.SetFile(file);
while (!xmlReader.AtEnd())
{
var type = xmlReader.ReadNext();
continue;
if (type == SXmlReader.StartElement)
{
var attributes = xmlReader.Attributes();
for (var idx = 0; idx < attributes.length; idx++)
print(attributes[idx].Name + ", " + attributes[idx].Value);
continue;
}
}
if (xmlReader.HasError()) {
print("Error");
}
file.Close();
Provide an interface for reading from and writing to files on disk.
Definition: Reshaper.h:1898
@ ReadOnly
The file is opened for reading.
Definition: Reshaper.h:1905
static SFile New(string name)
Construct a new file object to represent the file with the given name.
Allow to read xml files.
Definition: Reshaper.h:2786
string Name()
Return the local name of a StartElement, EndElement, or an EntityReference.
static SXmlReader New()
Default constructor to instantiate a XmlReader.
@ StartElement
The reader reports the start of an element.
Definition: Reshaper.h:2815
@ StartDocument
The reader reports the XML version number in DocumentVersion(), and the encoding as specified in the ...
Definition: Reshaper.h:2811
ErrorEnum Error()
Return the type of the current error, or NoError if no error occurred.
print(any arg)
Print to output the argument.

Member Enumeration Documentation

◆ ErrorEnum

The type of the current error.

Enumerator
NoError 

No error has occurred.

NotWellFormedError 

The parser internally raised an error due to the read XML not being well-formed.

PrematureEndOfDocumentError 

The input stream ended before a well-formed XML document was parsed.

UnexpectedElementError 

The parser encountered an element that was different to those it expected.

◆ TokenTypeEnum

The token type.

Enumerator
NoToken 

The reader has not yet read anything.

Invalid 

An error has occurred, reported in Error().

StartDocument 

The reader reports the XML version number in DocumentVersion(), and the encoding as specified in the XML document in DocumentEncoding().

EndDocument 

The reader reports the end of the document.

StartElement 

The reader reports the start of an element.

EndElement 

The reader reports the end of an element with NamespaceUri() and Name().

Characters 

IsWhitespace() returns true.

Comment 

The reader reports a comment in Text().

DTD 

The reader reports a DTD (Document Type Definition) in Text()

EntityReference 

The reader reports an entity reference that could not be resolved.

ProcessingInstruction 

The reader reports a processing instruction.

Constructor & Destructor Documentation

◆ SXmlReader()

SXmlReader::SXmlReader ( )

Default constructor to instantiate a XmlReader.

Member Function Documentation

◆ AtEnd()

boolean SXmlReader::AtEnd ( )

Return if the end of the file has been reached (all the file has been read or an error has occurred)

Returns
(boolean) True if the reader is at the end of the document or if an error has occurred. False otherwise.

◆ Attributes()

Array< Object > SXmlReader::Attributes ( )

Get the attributes of a StartElement.

Returns
(Array<Object>) A table of map containing all information for each element

◆ DocumentEncoding()

string SXmlReader::DocumentEncoding ( )

If the TokenType() is StartDocument, this function returns the encoding string as specified in the XML declaration. Otherwise an empty string is returned.

Returns
(string) The encoding string.

◆ DocumentVersion()

string SXmlReader::DocumentVersion ( )

If the TokenType() is StartDocument, this function returns the version string as specified in the XML declaration. Otherwise an empty string is returned.

Returns
(string) The version string.

◆ Error()

ErrorEnum SXmlReader::Error ( )

Return the type of the current error, or NoError if no error occurred.

Returns
(ErrorEnum) The type of the current error.

◆ HasError()

boolean SXmlReader::HasError ( )

Return if an error has occurred.

Returns
(boolean) True if an error has occurred, otherwise false.

◆ IsStandaloneDocument()

boolean SXmlReader::IsStandaloneDocument ( )

Return if this document has been declared standalone in the XML declaration. If no XML declaration has been parsed, this function returns false.

Returns
(boolean) True if this document has been declared standalone, otherwise false.

◆ IsWhitespace()

boolean SXmlReader::IsWhitespace ( )

Return if the reader reports characters that only consist of white-space.

Returns
(boolean) True if the reader reports characters that only consist of white-space, otherwise false.

◆ LineNumber()

number SXmlReader::LineNumber ( )

Return the current line number, starting with 1.

Returns
(number) The current line number.

◆ Name()

string SXmlReader::Name ( )

Return the local name of a StartElement, EndElement, or an EntityReference.

Returns
(string) The local name.

◆ NamespaceUri()

string SXmlReader::NamespaceUri ( )

Return the namespaceUri of a StartElement or EndElement.

Returns
(string) The namespaceUri.

◆ New()

static SXmlReader SXmlReader::New ( )
static

Default constructor to instantiate a XmlReader.

Returns
(SXmlReader) The new SXmlReader.

◆ ReadNext()

TokenTypeEnum SXmlReader::ReadNext ( )

Read the next token and return its type.

Returns
(TokenTypeEnum) The type of the next token.

◆ SetFile()

SXmlReader::SetFile ( SFile  file)

Set the current file to device. Setting the device resets reader.

Parameters
file(SFile) The name of the file.

◆ SkipCurrentElement()

SXmlReader::SkipCurrentElement ( )

Read until the end of the current element, skipping any child nodes. This function is useful for skipping unknown elements. The current element is the element matching the most recently parsed start element of which a matching end element has not yet been reached. When the parser has reached the end element, the current element becomes the parent element.

◆ Text()

string SXmlReader::Text ( )

Return the text of Characters, Comment, DTD, or EntityReference.

Returns
(string) The text.

◆ TokenString()

string SXmlReader::TokenString ( )

Return the reader's current token as string.

Returns
(string) The current token as string.

◆ TokenType()

TokenTypeEnum SXmlReader::TokenType ( )

Return the type of the current token.

Returns
(TokenTypeEnum) The type of the current token.

◆ toString()

string SXmlReader::toString ( )

Get the type of the variable.

Returns
(string) The type name