Alien-SVN

 view release on metacpan or  search on metacpan

src/subversion/subversion/include/svn_xml.h  view on Meta::CPAN






/*** Helpers for dealing with the data Expat gives us. ***/

/** Return the value associated with @a name in expat attribute array @a atts,
 * else return @c NULL.
 *
 * (There could never be a @c NULL attribute value in the XML,
 * although the empty string is possible.)
 *
 * @a atts is an array of c-strings: even-numbered indexes are names,
 * odd-numbers hold values.  If all is right, it should end on an
 * even-numbered index pointing to @c NULL.
 */
const char *
svn_xml_get_attr_value(const char *name,
                       const char *const *atts);



/* Converting between Expat attribute lists and APR hash tables. */


/** Create an attribute hash from @c va_list @a ap.
 *
 * The contents of @a ap are alternating <tt>char *</tt> keys and
 * <tt>char *</tt> vals, terminated by a final @c NULL falling on an
 * even index (zero-based).
 */
apr_hash_t *
svn_xml_ap_to_hash(va_list ap,
                   apr_pool_t *pool);

/** Create a hash that corresponds to Expat xml attribute list @a atts.
 *
 * The hash's keys and values are <tt>char *</tt>'s.
 *
 * @a atts may be NULL, in which case you just get an empty hash back
 * (this makes life more convenient for some callers).
 */
apr_hash_t *
svn_xml_make_att_hash(const char **atts,
                      apr_pool_t *pool);


/** Like svn_xml_make_att_hash(), but takes a hash and preserves any
 * key/value pairs already in it.
 */
void
svn_xml_hash_atts_preserving(const char **atts,
                             apr_hash_t *ht,
                             apr_pool_t *pool);

/** Like svn_xml_make_att_hash(), but takes a hash and overwrites
 * key/value pairs already in it that also appear in @a atts.
 */
void
svn_xml_hash_atts_overlaying(const char **atts,
                             apr_hash_t *ht,
                             apr_pool_t *pool);



/* Printing XML */

/** Create an XML header and return it in @a *str.
 *
 * Fully-formed XML documents should start out with a header,
 * something like <pre>
 *         \<?xml version="1.0" encoding="UTF-8"?\>
 * </pre>
 *
 * This function returns such a header.  @a *str must either be @c NULL, in
 * which case a new string is created, or it must point to an existing
 * string to be appended to. @a encoding must either be NULL, in which case
 * encoding information is omitted from the header, or must be the name of
 * the encoding of the XML document, such as "UTF-8".
 *
 * @since New in 1.7.
 */
void
svn_xml_make_header2(svn_stringbuf_t **str,
                     const char *encoding,
                     apr_pool_t *pool);

/** Like svn_xml_make_header2(), but does not emit encoding information.
 *
 * @deprecated Provided for backward compatibility with the 1.6 API.
 */
SVN_DEPRECATED
void
svn_xml_make_header(svn_stringbuf_t **str,
                    apr_pool_t *pool);


/** Store a new xml tag @a tagname in @a *str.
 *
 * If @a *str is @c NULL, set @a *str to a new stringbuf allocated
 * in @a pool, else append to the existing stringbuf there.
 *
 * Take the tag's attributes from varargs, a NULL-terminated list of
 * alternating <tt>char *</tt> key and <tt>char *</tt> val.  Do xml-escaping
 * on each val.
 *
 * @a style is one of the enumerated styles in @c svn_xml_open_tag_style.
 */
void
svn_xml_make_open_tag(svn_stringbuf_t **str,
                      apr_pool_t *pool,
                      enum svn_xml_open_tag_style style,
                      const char *tagname,
                      ...);


/** Like svn_xml_make_open_tag(), but takes a @c va_list instead of being
 * variadic.
 */
void
svn_xml_make_open_tag_v(svn_stringbuf_t **str,
                        apr_pool_t *pool,
                        enum svn_xml_open_tag_style style,
                        const char *tagname,
                        va_list ap);


/** Like svn_xml_make_open_tag(), but takes a hash table of attributes
 * (<tt>char *</tt> keys mapping to <tt>char *</tt> values).
 *
 * You might ask, why not just provide svn_xml_make_tag_atts()?
 *
 * The reason is that a hash table is the most natural interface to an
 * attribute list; the fact that Expat uses <tt>char **</tt> atts instead is
 * certainly a defensible implementation decision, but since we'd have
 * to have special code to support such lists throughout Subversion
 * anyway, we might as well write that code for the natural interface
 * (hashes) and then convert in the few cases where conversion is
 * needed.  Someday it might even be nice to change expat-lite to work
 * with apr hashes.
 *
 * See conversion functions svn_xml_make_att_hash() and
 * svn_xml_make_att_hash_overlaying().  Callers should use those to
 * convert Expat attr lists into hashes when necessary.
 */
void
svn_xml_make_open_tag_hash(svn_stringbuf_t **str,
                           apr_pool_t *pool,
                           enum svn_xml_open_tag_style style,
                           const char *tagname,
                           apr_hash_t *attributes);


/** Store an xml close tag @a tagname in @a str.
 *
 * If @a *str is @c NULL, set @a *str to a new stringbuf allocated
 * in @a pool, else append to the existing stringbuf there.
 */
void
svn_xml_make_close_tag(svn_stringbuf_t **str,
                       apr_pool_t *pool,
                       const char *tagname);


#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* SVN_XML_H */



( run in 1.045 second using v1.01-cache-2.11-cpan-7e98afdb40f )