xml.cpp revision 4e47bb772df0d04d1ded3e06354de547d52e2d06
/* Save the default entity resolver before someone has replaced it */ /** Used to provide some thread safety missing in libxml2 (see e.g. * XmlTreeBackend::read()) */ sxml;
/* XXX naming this xml will break with gcc-3.3 */ //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// * Composes a single message for the given error. The caller must free the * returned string using RTStrFree() when no more necessary. /* strip spaces, trailing EOLs and dot-like char */ //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// /** @todo change to RTFILE_O_DENY_WRITE where appropriate. */ /* check if we overflow int64_t and move to INT64_MAX first */ //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// return 0
/* nothing to read */;
//////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// bool operator()(
const char*
s1,
const char*
s2)
const // attributes, if this is an element; can be empty // child elements, if this is an element; can be empty * Private implementation. // go thru this element's attributes // go thru this element's child elements // recurse for this child element to get its own children * Returns the name of the node, which is either the element name or * the attribute name. For other node types it probably returns NULL. * Variant of nameEquals that checks the namespace as well. // name matches: then check namespaces as well // caller wants namespace: // but node has no namespace: * Returns the value of a node. If this node is an attribute, returns * the attribute value; if this node is an element, then this returns * the element text content. // libxml hides attribute values in another node created as a // single child of the attribute node, and it's in the content field * Copies the value of a node into the given integer variable. * Returns TRUE only if a value was found and was actually an * integer of the given type. * Copies the value of a node into the given integer variable. * Returns TRUE only if a value was found and was actually an * integer of the given type. * Copies the value of a node into the given integer variable. * Returns TRUE only if a value was found and was actually an * integer of the given type. * Copies the value of a node into the given integer variable. * Returns TRUE only if a value was found and was actually an * integer of the given type. * Returns the line number of the current node in the source XML file. * Useful for error messages. * Private element constructor. // NULL passed, then this is the root element * Builds a list of direct child elements of the current element that * match the given string; if pcszMatch is NULL, all direct child * @param children out: list of nodes to which children will be appended. * @param pcszMatch in: match string, or NULL to return all children. * @return Number of items appended to the list (0 if none). // export this child node if ... if ( (!
pcszMatch)
// the caller wants all nodes or * Returns the first child element whose name matches pcszMatch. * @param pcszNamespace Namespace prefix (e.g. "vbox") or NULL to match any namespace. * @param pcszMatch Element name to match. * Returns the first child element whose "id" attribute matches pcszId. * @param pcszId identifier to look for. * @return child element or NULL if not found. * Looks up the given attribute node in this element's attribute map. * With respect to namespaces, the internal attributes map stores namespace * prefixes with attribute names only if the attribute uses a non-default * namespace. As a result, the following rules apply: * -- To find attributes from a non-default namespace, pcszMatch must not * be prefixed with a namespace. * -- To find attributes from the default namespace (or if the document does * not use namespaces), pcszMatch must be prefixed with the namespace * For example, if the document uses the "vbox:" namespace by default, you * must omit "vbox:" from pcszMatch to find such attributes, whether they * are specifed in the xml or not. * Convenience method which attempts to find the attribute with the given * name and returns its value as a string. * @param pcszMatch name of attribute to find (see findAttribute() for namespace remarks) * @param ppcsz out: attribute value * @return TRUE if attribute was found and str was thus updated. * Convenience method which attempts to find the attribute with the given * name and returns its value as a string. * @param pcszMatch name of attribute to find (see findAttribute() for namespace remarks) * @param str out: attribute value; overwritten only if attribute was found * @return TRUE if attribute was found and str was thus updated. * Like getAttributeValue (ministring variant), but makes sure that all backslashes * are converted to forward slashes. * Convenience method which attempts to find the attribute with the given * name and returns its value as a signed integer. This calls * RTStrToInt32Ex internally and will only output the integer if that * function returns no error. * @param pcszMatch name of attribute to find (see findAttribute() for namespace remarks) * @param i out: attribute value; overwritten only if attribute was found * @return TRUE if attribute was found and str was thus updated. * Convenience method which attempts to find the attribute with the given * name and returns its value as an unsigned integer.This calls * RTStrToUInt32Ex internally and will only output the integer if that * function returns no error. * @param pcszMatch name of attribute to find (see findAttribute() for namespace remarks) * @param i out: attribute value; overwritten only if attribute was found * @return TRUE if attribute was found and str was thus updated. * Convenience method which attempts to find the attribute with the given * name and returns its value as a signed long integer. This calls * RTStrToInt64Ex internally and will only output the integer if that * function returns no error. * @param pcszMatch name of attribute to find (see findAttribute() for namespace remarks) * @param i out: attribute value * @return TRUE if attribute was found and str was thus updated. * Convenience method which attempts to find the attribute with the given * name and returns its value as an unsigned long integer.This calls * RTStrToUInt64Ex internally and will only output the integer if that * function returns no error. * @param pcszMatch name of attribute to find (see findAttribute() for namespace remarks) * @param i out: attribute value; overwritten only if attribute was found * @return TRUE if attribute was found and str was thus updated. * Convenience method which attempts to find the attribute with the given * name and returns its value as a boolean. This accepts "true", "false", * "yes", "no", "1" or "0" as valid values. * @param pcszMatch name of attribute to find (see findAttribute() for namespace remarks) * @param f out: attribute value; overwritten only if attribute was found * @return TRUE if attribute was found and str was thus updated. * Creates a new child element node and appends it to the list // we must be an element, not an attribute // libxml side: create new node * Creates a content node and appends it to the list of children // libxml side: create new node * Sets the given attribute; overloaded version for const char *. * If an attribute with the given name exists, it is overwritten, * otherwise a new attribute is created. Returns the attribute node * that was either created or changed. // libxml side: xmlNewProp creates an attribute // C++ side: create an attribute node around it // overwrite existing libxml attribute node // and fix our existing C++ side around it * Like setAttribute (ministring variant), but replaces all backslashes with forward slashes * before calling that one. * Sets the given attribute; overloaded version for int32_t. * If an attribute with the given name exists, it is overwritten, * otherwise a new attribute is created. Returns the attribute node * that was either created or changed. char szValue[
12];
// negative sign + 10 digits + \0 * Sets the given attribute; overloaded version for uint32_t. * If an attribute with the given name exists, it is overwritten, * otherwise a new attribute is created. Returns the attribute node * that was either created or changed. char szValue[
11];
// 10 digits + \0 * Sets the given attribute; overloaded version for int64_t. * If an attribute with the given name exists, it is overwritten, * otherwise a new attribute is created. Returns the attribute node * that was either created or changed. char szValue[
21];
// negative sign + 19 digits + \0 * Sets the given attribute; overloaded version for uint64_t. * If an attribute with the given name exists, it is overwritten, * otherwise a new attribute is created. Returns the attribute node * that was either created or changed. char szValue[
21];
// 20 digits + \0 * Sets the given attribute to the given uint32_t, outputs a hexadecimal string. * If an attribute with the given name exists, it is overwritten, * otherwise a new attribute is created. Returns the attribute node * that was either created or changed. char szValue[
11];
// "0x" + 8 digits + \0 * Sets the given attribute; overloaded version for bool. * If an attribute with the given name exists, it is overwritten, * otherwise a new attribute is created. Returns the attribute node * that was either created or changed. * Private constructor for a new attribute node. This one is special: * in ppcszKey, it returns a pointer to a string buffer that should be * used to index the attribute correctly with namespaces. // not default namespace: * Handy convenience helper for looping over all child elements. Create an * instance of NodesLoop on the stack and call this method until it returns * xml::ElementNode node; // should point to an element * xml::NodesLoop loop(node, "child"); // find all "child" elements under node * const xml::ElementNode *pChild = NULL; * while (pChild = loop.forAllNodes()) //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// 1);
// recursive == copy all * private method to refresh all internal structures after the internal pDocument * has changed. Called from XmlFileParser::read(). m->reset() must have been * called before to make sure all members except the internal pDocument are clean. * Returns the root element of the document, or NULL if the document is empty. * Returns the root element of the document, or NULL if the document is empty. * Creates a new element node and sets it as the root element. This will * only work if the document is empty; otherwise EDocumentNotEmpty is thrown. // libxml side: create document, create root node // add document global comment if specified //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// * Parse the given buffer and fills the given Document object with its contents. * Throws XmlError on parsing errors. * The document that is passed in will be reset before being filled if not empty. * @param pvBuf in: memory buffer to parse. * @param cbSize in: size of the memory buffer. * @param strFilename in: name fo file to parse. * @param doc out: document to be reset and filled with data according to file contents. // global.setExternalEntityLoader(ExternalEntityLoader); //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// * Reads the given file and fills the given Document object with its contents. * Throws XmlError on parsing errors. * The document that is passed in will be reset before being filled if not empty. * @param strFilename in: name fo file to parse. * @param doc out: document to be reset and filled with data according to file contents. // global.setExternalEntityLoader(ExternalEntityLoader); /* To prevent throwing exceptions while inside libxml2 code, we catch * them and forward to our level using a couple of variables. */ //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /* serialize to the stream */ /* look if there was a forwarded exception from the lower level */ // if (m->trappedErr.get() != NULL) // m->trappedErr->rethrow(); /* there must be an exception from the Output implementation, * otherwise the save operation must always succeed. */ /* Empty string and directory spec must be avoid. */ /* Construct both filenames first to ease error handling. */ /* Write the XML document to the temporary file. */ /* Make a backup of any existing file (ignore failure). */ /* Commit the temporary file. Just leave the tmp file behind on failure. */ /* Flush the directory changes (required on linux at least). */ /* To prevent throwing exceptions while inside libxml2 code, we catch * them and forward to our level using a couple of variables. */