Ghidra 11.3.2
Ghidra internal decompiler documentation.
Loading...
Searching...
No Matches
xml.hh File Reference

Lightweight (and incomplete) XML parser for marshaling data to and from the decompiler. More...

#include "types.h"
#include <fstream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
Include dependency graph for xml.hh:

Classes

class  ghidra::Attributes
 The attributes for a single XML element. More...
 
class  ghidra::ContentHandler
 The SAX interface for parsing XML documents. More...
 
class  ghidra::Element
 An XML element. A node in the DOM tree. More...
 
class  ghidra::Document
 A complete in-memory XML document. More...
 
class  ghidra::TreeHandler
 A SAX interface implementation for constructing an in-memory DOM model. More...
 
class  ghidra::DocumentStorage
 A container for parsed XML documents. More...
 
struct  ghidra::DecoderError
 An exception thrown by the XML parser. More...
 

Typedefs

typedef void * ghidra::Locator
 Placeholder for a document locator object.
 
typedef vector< Element * > ghidra::List
 A list of XML elements.
 

Functions

int4 ghidra::xml_parse (istream &i, ContentHandler *hand, int4 dbg=0)
 Start-up the XML parser given a stream and a handler.
 
Documentghidra::xml_tree (istream &i)
 Parse the given XML stream into an in-memory document.
 
void ghidra::xml_escape (ostream &s, const char *str)
 Send the given character array to a stream, escaping characters with special XML meaning.
 
void ghidra::a_v (ostream &s, const string &attr, const string &val)
 Output an XML attribute name/value pair to stream.
 
void ghidra::a_v_i (ostream &s, const string &attr, intb val)
 Output the given signed integer as an XML attribute value.
 
void ghidra::a_v_u (ostream &s, const string &attr, uintb val)
 Output the given unsigned integer as an XML attribute value.
 
void ghidra::a_v_b (ostream &s, const string &attr, bool val)
 Output the given boolean value as an XML attribute.
 
bool ghidra::xml_readbool (const string &attr)
 Read an XML attribute value as a boolean.
 

Detailed Description

Lightweight (and incomplete) XML parser for marshaling data to and from the decompiler.

Function Documentation

◆ a_v()

void ghidra::a_v ( ostream &  s,
const string &  attr,
const string &  val 
)
inline

Output an XML attribute name/value pair to stream.

Parameters
sis the output stream
attris the name of the attribute
valis the attribute value

References ghidra::a_v().

Referenced by ghidra::a_v(), ghidra::XmlEncode::writeSpace(), and ghidra::XmlEncode::writeString().

◆ a_v_b()

void ghidra::a_v_b ( ostream &  s,
const string &  attr,
bool  val 
)
inline

Output the given boolean value as an XML attribute.

Parameters
sis the output stream
attris the name of the attribute
valis the given boolean value

References ghidra::a_v_b().

Referenced by ghidra::a_v_b(), and ghidra::XmlEncode::writeBool().

◆ a_v_i()

void ghidra::a_v_i ( ostream &  s,
const string &  attr,
intb  val 
)
inline

Output the given signed integer as an XML attribute value.

Parameters
sis the output stream
attris the name of the attribute
valis the given integer value

References ghidra::a_v_i().

Referenced by ghidra::a_v_i(), and ghidra::XmlEncode::writeSignedInteger().

◆ a_v_u()

void ghidra::a_v_u ( ostream &  s,
const string &  attr,
uintb  val 
)
inline

Output the given unsigned integer as an XML attribute value.

Parameters
sis the output stream
attris the name of the attribute
valis the given unsigned integer value

References ghidra::a_v_u().

Referenced by ghidra::a_v_u(), and ghidra::XmlEncode::writeUnsignedInteger().

◆ xml_escape()

void ghidra::xml_escape ( ostream &  s,
const char *  str 
)

Send the given character array to a stream, escaping characters with special XML meaning.

This makes the following character substitutions:

  • '<' => "&lt;"
  • '>' => "&gt;"
  • '&' => "&amp;"
  • '"' => "&quot;"
  • '\'' => "&apos;"
Parameters
sis the stream to write to
stris the given character array to escape

◆ xml_parse()

int4 ghidra::xml_parse ( istream &  i,
ContentHandler hand,
int4  dbg = 0 
)

Start-up the XML parser given a stream and a handler.

This runs the low-level XML parser.

Parameters
iis the given stream to get character data from
handis the ContentHandler that stores or processes the XML content events
dbgis non-zero if the parser should output debug information during its parse
Returns
0 if there is no error during parsing or a (non-zero) error condition

◆ xml_readbool()

bool ghidra::xml_readbool ( const string &  attr)
inline

Read an XML attribute value as a boolean.

This method is intended to recognize the strings, "true", "yes", and "1" as a true value. Anything else is returned as false.

Parameters
attris the given XML attribute value (as a string)
Returns
either true or false

References ghidra::xml_readbool().

Referenced by ghidra::XmlDecode::readBool(), ghidra::XmlDecode::readBool(), and ghidra::xml_readbool().

◆ xml_tree()

Document * ghidra::xml_tree ( istream &  i)

Parse the given XML stream into an in-memory document.

The stream is parsed using the standard ContentHandler for producing an in-memory DOM representation of the XML document.

Parameters
iis the given stream
Returns
the in-memory XML document