37 static string bogus_uri;
40 vector<string *> name;
41 vector<string *> value;
45 for(uint4 i=0;i<name.size();++i) {
delete name[i];
delete value[i]; }
48 const string &
getelemURI(
void)
const {
return bogus_uri; }
49 const string &
getelemName(
void)
const {
return *elementname; }
50 void add_attribute(
string *nm,
string *vl) { name.push_back(nm); value.push_back(vl); }
53 const string &
getURI(int4 i)
const {
return bogus_uri; }
55 const string &
getQName(int4 i)
const {
return *name[i]; }
61 const string &
getValue(int4 i)
const {
return *value[i]; }
64 const string &
getValue(
const string &qualifiedName)
const {
65 for(uint4 i=0;i<name.size();++i)
66 if (*name[i] == qualifiedName)
return *value[i];
80 virtual void setDocumentLocator(
Locator locator)=0;
81 virtual void startDocument(
void)=0;
82 virtual void endDocument(
void)=0;
83 virtual void startPrefixMapping(
const string &prefix,
const string &uri)=0;
84 virtual void endPrefixMapping(
const string &prefix)=0;
92 virtual void startElement(
const string &namespaceURI,
const string &localName,
93 const string &qualifiedName,
const Attributes &atts)=0;
100 virtual void endElement(
const string &namespaceURI,
const string &localName,
101 const string &qualifiedName)=0;
108 virtual void characters(
const char *text,int4 start,int4 length)=0;
115 virtual void ignorableWhitespace(
const char *text,int4 start,int4 length)=0;
120 virtual void setVersion(
const string &version)=0;
125 virtual void setEncoding(
const string &encoding)=0;
131 virtual void processingInstruction(
const string &target,
const string &data)=0;
136 virtual void skippedEntity(
const string &name)=0;
141 virtual void setError(
const string &errmsg)=0;
145 typedef vector<Element *>
List;
154 vector<string> value;
170 content.append(str+start,length); }
182 attr.push_back(nm); value.push_back(vl); }
185 const string &
getName(
void)
const {
return name; }
195 const string &getAttributeValue(
const string &nm)
const;
229 virtual void startElement(
const string &namespaceURI,
const string &localName,
230 const string &qualifiedName,
const Attributes &atts);
231 virtual void endElement(
const string &namespaceURI,
const string &localName,
232 const string &qualifiedName);
233 virtual void characters(
const char *text,int4 start,int4 length);
239 virtual void setError(
const string &errmsg) { error = errmsg; }
240 const string &
getError(
void)
const {
return error; }
250 vector<Document *> doclist;
251 map<string,const Element *> tagmap;
261 Document *parseDocument(istream &s);
269 Document *openDocument(
const string &filename);
275 void registerTag(
const Element *el);
281 const Element *getTag(
const string &nm)
const;
321 extern void xml_escape(ostream &s,
const char *str);
330 inline void a_v(ostream &s,
const string &attr,
const string &val)
333 s <<
' ' << attr <<
"=\"";
343 inline void a_v_i(ostream &s,
const string &attr,intb val)
346 s <<
' ' << attr <<
"=\"" << dec << val <<
"\"";
354 inline void a_v_u(ostream &s,
const string &attr,uintb val)
357 s <<
' ' << attr <<
"=\"0x" << hex << val <<
"\"";
365 inline void a_v_b(ostream &s,
const string &attr,
bool val)
368 s <<
' ' << attr <<
"=\"";
385 if (attr.size()==0)
return false;
386 char firstc = attr[0];
387 if (firstc==
't')
return true;
388 if (firstc==
'1')
return true;
389 if (firstc==
'y')
return true;
A container for parsed XML documents.
Definition: xml.hh:249
virtual void processingInstruction(const string &target, const string &data)
Callback for a formal processing instruction seen in the current document.
Definition: xml.hh:235
void add_attribute(string *nm, string *vl)
Add a formal attribute.
Definition: xml.hh:50
const string & getValue(const string &qualifiedName) const
Get the value of the attribute with the given qualified name.
Definition: xml.hh:64
Attributes(string *el)
Construct from element name string.
Definition: xml.hh:43
void xml_escape(ostream &s, const char *str)
Send the given character array to a stream, escaping characters with special XML meaning.
const List & getChildren(void) const
Get the list of child elements.
Definition: xml.hh:186
virtual void skippedEntity(const string &name)
Callback for an XML entity skipped by the parser.
Definition: xml.hh:238
~Attributes(void)
Destructor.
Definition: xml.hh:44
string explain
Explanatory string.
Definition: xml.hh:289
const string & getContent(void) const
Get the character content of this element.
Definition: xml.hh:187
Document(void)
Construct an (empty) document.
Definition: xml.hh:208
void * Locator
Placeholder for a document locator object.
Definition: xml.hh:71
void setName(const string &nm)
Set the local name of the element.
Definition: xml.hh:161
Element * parent
The parent Element (or null)
Definition: xml.hh:156
void a_v_b(ostream &s, const string &attr, bool val)
Output the given boolean value as an XML attribute.
Definition: xml.hh:365
vector< Element * > List
A list of XML elements.
Definition: xml.hh:144
void a_v(ostream &s, const string &attr, const string &val)
Output an XML attribute name/value pair to stream.
Definition: xml.hh:330
const string & getAttributeValue(int4 i) const
Get the value of the i-th attribute.
Definition: xml.hh:199
void a_v_u(ostream &s, const string &attr, uintb val)
Output the given unsigned integer as an XML attribute value.
Definition: xml.hh:354
const string & getValue(int4 i) const
Get the value of the i-th attribute.
Definition: xml.hh:61
virtual void setEncoding(const string &val)
Set the character encoding as specified by the current document.
Definition: xml.hh:237
void addAttribute(const string &nm, const string &vl)
Add a new name/value attribute pair to this element.
Definition: xml.hh:181
virtual void setError(const string &errmsg)
Callback for handling an error condition during XML parsing.
Definition: xml.hh:239
TreeHandler(Element *rt)
Constructor given root Element.
Definition: xml.hh:222
const string & getelemName(void) const
Get the name of this element.
Definition: xml.hh:49
The attributes for a single XML element.
Definition: xml.hh:36
virtual void setDocumentLocator(Locator locator)
Set the Locator object for documents.
Definition: xml.hh:224
const string & getLocalName(int4 i) const
Get the local name of the i-th attribute.
Definition: xml.hh:54
virtual void startPrefixMapping(const string &prefix, const string &uri)
Start a new prefix to namespace URI mapping.
Definition: xml.hh:227
const string & getQName(int4 i) const
Get the qualified name of the i-th attribute.
Definition: xml.hh:55
An exception thrown by the XML parser.
Definition: xml.hh:288
virtual void endPrefixMapping(const string &prefix)
Finish the current prefix.
Definition: xml.hh:228
Element * getParent(void) const
Get the parent Element.
Definition: xml.hh:184
The SAX interface for parsing XML documents.
Definition: xml.hh:77
const string & getName(void) const
Get the local name of this element.
Definition: xml.hh:185
An XML element. A node in the DOM tree.
Definition: xml.hh:150
Element * getRoot(void) const
Get the root Element of the document.
Definition: xml.hh:209
XmlError(const string &s)
Constructor.
Definition: xml.hh:290
void addChild(Element *child)
Add a new child Element to the model, with this as the parent.
Definition: xml.hh:175
A complete in-memory XML document.
Definition: xml.hh:206
bool xml_readbool(const string &attr)
Read an XML attribute value as a boolean.
Definition: xml.hh:382
virtual void setVersion(const string &val)
Set the XML version as specified by the current document.
Definition: xml.hh:236
int4 getNumAttributes(void) const
Get the number of attributes for this element.
Definition: xml.hh:197
const string & getURI(int4 i) const
Get the namespace URI associated with the i-th attribute.
Definition: xml.hh:53
Element(Element *par)
Constructor given a parent Element.
Definition: xml.hh:159
void addContent(const char *str, int4 start, int4 length)
Append new character content to this element.
Definition: xml.hh:168
Document * xml_tree(istream &i)
Parse the given XML stream into an in-memory document.
const string & getError(void) const
Get the current error message.
Definition: xml.hh:240
void a_v_i(ostream &s, const string &attr, intb val)
Output the given signed integer as an XML attribute value.
Definition: xml.hh:343
int4 xml_parse(istream &i, ContentHandler *hand, int4 dbg=0)
Start-up the XML parser given a stream and a handler.
A SAX interface implementation for constructing an in-memory DOM model.
Definition: xml.hh:217
virtual void ignorableWhitespace(const char *text, int4 start, int4 length)
Callback with whitespace character data for the current XML element.
Definition: xml.hh:234
List children
A list of child Element objects.
Definition: xml.hh:157
virtual void startDocument(void)
Start processing a new XML document.
Definition: xml.hh:225
virtual ~ContentHandler(void)
Destructor.
Definition: xml.hh:79
const string & getAttributeName(int4 i) const
Get the name of the i-th attribute.
Definition: xml.hh:198
int4 getLength(void) const
Get the number of attributes associated with the element.
Definition: xml.hh:52
virtual void endDocument(void)
End processing for the current XML document.
Definition: xml.hh:226
const string & getelemURI(void) const
Get the namespace URI associated with this element.
Definition: xml.hh:48