RPC-XML-Deparser-XS

 view release on metacpan or  search on metacpan

libxwrite.c  view on Meta::CPAN


    this->element_has_children = TRUE;
    this->last_node_was_text   = FALSE;
}

void xwrite_start_element(XWrite* this, const gchar* qname) {
    xwrite_finish_element(this);

    xwrite_indent(this);
    xwrite_copy(this, "<");
    xwrite_copy(this, qname);

    this->level++;
    this->element_is_incomplete = TRUE;
    this->element_has_children  = FALSE;
    this->last_node_was_text    = FALSE;
}

void xwrite_end_element(XWrite* this, const gchar* qname) {
    g_assert(this->level > 0);
    
    this->level--;

    if (G_LIKELY(this->element_has_children)) {
	xwrite_finish_element(this);
	xwrite_indent(this);
	xwrite_copy(this, "</");
	xwrite_copy(this, qname);
	xwrite_copy(this, ">");
    }
    else {
	this->element_is_incomplete = FALSE;
	xwrite_copy(this, "/>");
    }

    this->last_node_was_text = FALSE;

    if (G_LIKELY(this->level > 0)) {
	this->element_has_children = TRUE;
    }
}

void xwrite_add_attribute(XWrite* this, const gchar* qname, const gchar* value) {
    g_assert(this->element_is_incomplete);

    xwrite_copy(this, " ");
    xwrite_copy(this, qname);
    xwrite_copy(this, "=\"");
    xwrite_escape(this, value);
    xwrite_copy(this, "\"");
}

void xwrite_add_text(XWrite* this, const gchar* str) {
    xwrite_finish_element(this);
    xwrite_escape(this, str);
    
    this->element_has_children = TRUE;
    this->last_node_was_text   = TRUE;
}

void xwrite_add_CDATA(XWrite* this, const gchar* cdata) {

#if HAVE_STRSTR
    g_assert(strstr(cdata, "]]>") == NULL);
#endif

    xwrite_finish_element(this);
    xwrite_copy(this, "<![CDATA[");
    xwrite_copy(this, cdata);
    xwrite_copy(this, "]]>");

    this->element_has_children = TRUE;
    this->last_node_was_text   = TRUE;
}

void xwrite_add_base64(XWrite* this, const gchar* str, gsize len) {
    gchar* encoded = g_base64_encode(str, len);
    
    xwrite_add_text(this, encoded);
    g_free(encoded);
}



( run in 0.903 second using v1.01-cache-2.11-cpan-9581c071862 )