std::string XMLSchema::xml() const { xmlBuffer *b = xmlBufferCreate(); xmlTextWriterPtr w = xmlNewTextWriterMemory(b, 0); xmlTextWriterSetIndent(w, 1); xmlTextWriterStartDocument(w, NULL, "utf-8", NULL); xmlTextWriterStartElementNS(w, (const xmlChar*)"pc", (const xmlChar*)"PointCloudSchema", NULL); xmlTextWriterWriteAttributeNS(w, (const xmlChar*) "xmlns", (const xmlChar*)"pc", NULL, (const xmlChar*)"http://pointcloud.org/schemas/PC/"); xmlTextWriterWriteAttributeNS(w, (const xmlChar*)"xmlns", (const xmlChar*)"xsi", NULL, (const xmlChar*)"http://www.w3.org/2001/XMLSchema-instance"); writeXml(w); xmlTextWriterEndElement(w); xmlTextWriterEndDocument(w); std::string output((const char *)b->content, b->use); xmlFreeTextWriter(w); xmlBufferFree(b); return output; }
static void writeAttributes(Serialization *serialization, DFNode *element) { // Sort the keys by their tag, to ensure that we always write attributes out in the same order. // This is important for automated tests which rely on consistent output for a given XML tree. DFAttribute *attrs = (DFAttribute *)xmalloc(element->attrsCount*sizeof(DFAttribute)); memcpy(attrs,element->attrs,element->attrsCount*sizeof(DFAttribute)); qsort(attrs,element->attrsCount,sizeof(DFAttribute),compareAttrs); for (unsigned int i = 0; i < element->attrsCount; i++) { Tag tag = attrs[i].tag; const TagDecl *tagDecl = DFNameMapNameForTag(serialization->doc->map,tag); assert(tagDecl != NULL); const NamespaceDecl *nsDecl = DFNameMapNamespaceForID(serialization->doc->map,tagDecl->namespaceID); assert(nsDecl != NULL); const xmlChar *prefix = (const xmlChar *)nsDecl->prefix; const xmlChar *localName = (const xmlChar *)tagDecl->localName; const xmlChar *value = (const xmlChar *)attrs[i].value; if (serialization->html && (tagDecl->namespaceID == NAMESPACE_HTML)) xmlTextWriterWriteAttribute(serialization->writer,localName,value); else xmlTextWriterWriteAttributeNS(serialization->writer,prefix,localName,NULL,value); } free(attrs); }
axis2_status_t AXIS2_CALL axis2_libxml2_writer_wrapper_write_attribute_with_namespace_prefix( axiom_xml_writer_t * writer, const axutil_env_t * env, axis2_char_t * localname, axis2_char_t * value, axis2_char_t * namespace_uri, axis2_char_t * prefix) { axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; int status = 0; AXIS2_ENV_CHECK(env, AXIS2_FAILURE); AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE); AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE); AXIS2_PARAM_CHECK(env->error, prefix, AXIS2_FAILURE); if(!value) { value = ""; } writer_impl = AXIS2_INTF_TO_IMPL(writer); status = xmlTextWriterWriteAttributeNS(writer_impl->xml_writer, BAD_CAST prefix, BAD_CAST localname, BAD_CAST NULL, BAD_CAST value); if(status < 0) { AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_ATTRIBUTE_WITH_NAMESPACE_PREFIX, AXIS2_FAILURE); return AXIS2_FAILURE; } return AXIS2_SUCCESS; }
bool TasksetWriter::write(const std::string& filename, vector<Task*>& taskset) const { xmlDocPtr doc; tDebug() << "Writing Taskset to XML file: " << filename; xmlTextWriterPtr writer; writer = xmlNewTextWriterDoc(&doc, 0); xmlTextWriterSetIndent(writer, 1); if (xmlTextWriterSetIndentString(writer, (const xmlChar*) " ") != 0) { tError() << "Fehler beim Setzen des Einrueckens!"; } xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL); xmlTextWriterWriteComment(writer, (xmlChar*) "Hier kommen die Tasks"); xmlTextWriterStartElement(writer, (xmlChar*) "taskset"); xmlTextWriterWriteAttributeNS(writer, (xmlChar*) "xsi", (xmlChar*) "schemaLocation", (xmlChar*) "http://www.w3.org/2001/XMLSchema-instance", (xmlChar*) "http://www.tmsxmlns.com taskset.xsd"); xmlTextWriterWriteAttribute(writer, (xmlChar*) "xmlns", (xmlChar*) "http://www.tmsxmlns.com"); xmlTextWriterWriteRaw(writer, (xmlChar*) "\n"); for (size_t i = 0; i < taskset.size(); i++) { xmlTextWriterWriteRaw(writer, (xmlChar*) "\n"); //taskset[i]->write(writer); taskset[i]->writeToXML(writer); xmlTextWriterWriteRaw(writer, (xmlChar*) "\n"); } xmlTextWriterEndElement(writer); // close TaskSet xmlTextWriterEndDocument(writer); xmlFreeTextWriter(writer); xmlSaveFile(filename.c_str(), doc); xmlNodePtr cur = xmlDocGetRootElement(doc); if (cur == NULL) { tError() << "Empty document."; xmlFreeDoc(doc); return false; } if (xmlStrcmp(cur->name, (const xmlChar *) "taskset")) { tError() << "Document of the wrong type, root node != taskset"; xmlFreeDoc(doc); return false; } if (isValid(doc) > 0) { tDebug() << "Written document is valid"; } else { tError() << "Written document is invalid"; xmlFreeDoc(doc); return false; } xmlFreeDoc(doc); return true; }
bool c_XMLWriter::t_writeattributens(const String& prefix, const String& name, const String& uri, const String& content) { if (xmlValidateName((xmlChar*)name.data(), 0)) { raise_warning("invalid attribute name: %s", name.data()); return false; } int ret = -1; if (m_ptr) { ret = xmlTextWriterWriteAttributeNS(m_ptr, (xmlChar*)prefix.data(), (xmlChar*)name.data(), (xmlChar*)uri.data(), (xmlChar*)content.data()); } return ret != -1; }
bool c_xmlwriter::t_writeattributens(CStrRef prefix, CStrRef name, CStrRef uri, CStrRef content) { if (xmlValidateName((xmlChar*)name.data(), 0)) { raise_warning("invalid attribute name: %s", name.data()); return false; } int ret = -1; if (m_ptr) { ret = xmlTextWriterWriteAttributeNS(m_ptr, (xmlChar*)prefix.data(), (xmlChar*)name.data(), (xmlChar*)uri.data(), (xmlChar*)content.data()); } return ret != -1; }
bool c_XMLWriter::t_writeattributens(CStrRef prefix, CStrRef name, CStrRef uri, CStrRef content) { INSTANCE_METHOD_INJECTION_BUILTIN(XMLWriter, XMLWriter::writeattributens); if (xmlValidateName((xmlChar*)name.data(), 0)) { raise_warning("invalid attribute name: %s", name.data()); return false; } int ret = -1; if (m_ptr) { ret = xmlTextWriterWriteAttributeNS(m_ptr, (xmlChar*)prefix.data(), (xmlChar*)name.data(), (xmlChar*)uri.data(), (xmlChar*)content.data()); } return ret != -1; }
static void writeNamespaceDeclarations(Serialization *serialization, DFNode *node) { NamespaceID count = DFNameMapNamespaceCount(serialization->doc->map); char *used = (char *)xcalloc(1,count); findUsedNamespaces(serialization->doc,node,used,count); for (NamespaceID nsId = 1; nsId < count; nsId++) { // don't write null namespace if (used[nsId]) { const NamespaceDecl *nsDecl = DFNameMapNamespaceForID(serialization->doc->map,nsId); const xmlChar *prefix = (const xmlChar *)nsDecl->prefix; const xmlChar *URI = (const xmlChar *)nsDecl->namespaceURI; if (nsId == serialization->defaultNS) xmlTextWriterWriteAttribute(serialization->writer,(const xmlChar *)"xmlns",URI); else xmlTextWriterWriteAttributeNS(serialization->writer,(const xmlChar *)"xmlns",prefix,NULL,URI); } } free(used); }
static char * create_resource_list_xml(const LinphoneFriendList *list) { char *xml_content = NULL; MSList *elem; xmlBufferPtr buf; xmlTextWriterPtr writer; int err; if (ms_list_size(list->friends) <= 0) return NULL; buf = xmlBufferCreate(); if (buf == NULL) { ms_error("%s: Error creating the XML buffer", __FUNCTION__); return NULL; } writer = xmlNewTextWriterMemory(buf, 0); if (writer == NULL) { ms_error("%s: Error creating the XML writer", __FUNCTION__); return NULL; } xmlTextWriterSetIndent(writer,1); err = xmlTextWriterStartDocument(writer, "1.0", "UTF-8", NULL); if (err >= 0) { err = xmlTextWriterStartElementNS(writer, NULL, (const xmlChar *)"resource-lists", (const xmlChar *)"urn:ietf:params:xml:ns:resource-lists"); } if (err >= 0) { err = xmlTextWriterWriteAttributeNS(writer, (const xmlChar *)"xmlns", (const xmlChar *)"xsi", NULL, (const xmlChar *)"http://www.w3.org/2001/XMLSchema-instance"); } if (err>= 0) { err = xmlTextWriterStartElement(writer, (const xmlChar *)"list"); } for (elem = list->friends; elem != NULL; elem = elem->next) { LinphoneFriend *friend = (LinphoneFriend *)elem->data; char *uri = linphone_address_as_string_uri_only(friend->uri); if (err >= 0) { err = xmlTextWriterStartElement(writer, (const xmlChar *)"entry"); } if (err >= 0) { err = xmlTextWriterWriteAttribute(writer, (const xmlChar *)"uri", (const xmlChar *)uri); } if (err >= 0) { /* Close the "entry" element. */ err = xmlTextWriterEndElement(writer); } if (uri) ms_free(uri); } if (err >= 0) { /* Close the "list" element. */ err = xmlTextWriterEndElement(writer); } if (err >= 0) { /* Close the "resource-lists" element. */ err = xmlTextWriterEndElement(writer); } if (err >= 0) { err = xmlTextWriterEndDocument(writer); } if (err > 0) { /* xmlTextWriterEndDocument returns the size of the content. */ xml_content = ms_strdup((char *)buf->content); } xmlFreeTextWriter(writer); xmlBufferFree(buf); return xml_content; }
gboolean biji_lazy_serialize_internal (BijiLazySerializer *self) { BijiLazySerializerPrivate *priv = self->priv; GList *tags; GdkRGBA color; gchar *date, *color_str; gboolean retval; const gchar *path; GTimeVal time = {0, 0}; priv->writer = xmlNewTextWriterMemory(priv->buf, 0); // Header xmlTextWriterStartDocument (priv->writer,"1.0","utf-8",NULL); xmlTextWriterStartElement (priv->writer, BAD_CAST "note"); xmlTextWriterWriteAttributeNS (priv->writer, NULL, BAD_CAST "version",NULL, BAD_CAST "1"); xmlTextWriterWriteAttributeNS (priv->writer, BAD_CAST "xmlns", BAD_CAST "link", NULL, BAD_CAST "http://projects.gnome.org/bijiben/link"); xmlTextWriterWriteAttributeNS (priv->writer, BAD_CAST "xmlns", BAD_CAST "size", NULL, BAD_CAST "http://projects.gnome.org/bijiben/size"); xmlTextWriterWriteAttributeNS (priv->writer, NULL, BAD_CAST "xmlns", NULL, BAD_CAST "http://projects.gnome.org/bijiben"); // <Title> serialize_node (priv->writer, "title", (gchar*) biji_item_get_title (BIJI_ITEM (priv->note))); // <text> xmlTextWriterWriteRaw(priv->writer, BAD_CAST "\n "); xmlTextWriterStartElement(priv->writer, BAD_CAST "text"); xmlTextWriterWriteAttributeNS(priv->writer, BAD_CAST "xml", BAD_CAST "space", NULL, BAD_CAST "preserve"); serialize_html (self); // </text> xmlTextWriterEndElement(priv->writer); // <last-change-date> time.tv_sec = biji_item_get_mtime (BIJI_ITEM (priv->note)); date = g_time_val_to_iso8601 (&time); if (date) { serialize_node (priv->writer, "last-change-date", date); g_free (date); } time.tv_sec = biji_note_obj_get_last_metadata_change_date (priv->note); date = g_time_val_to_iso8601 (&time); if (date) { serialize_node (priv->writer, "last-metadata-change-date", date); g_free (date); } time.tv_sec = biji_note_obj_get_create_date (priv->note); date = g_time_val_to_iso8601 (&time); if (date) { serialize_node (priv->writer, "create-date", date); g_free (date); } serialize_node (priv->writer, "cursor-position", "0"); serialize_node (priv->writer, "selection-bound-position", "0"); serialize_node (priv->writer, "width", "0"); serialize_node (priv->writer, "height", "0"); serialize_node (priv->writer, "x", "0"); serialize_node (priv->writer, "y", "0"); if (biji_note_obj_get_rgba (priv->note, &color)) { color_str = gdk_rgba_to_string (&color); serialize_node (priv->writer, "color", color_str); g_free (color_str); } //<tags> xmlTextWriterWriteRaw(priv->writer, BAD_CAST "\n "); xmlTextWriterStartElement (priv->writer, BAD_CAST "tags"); tags = biji_note_obj_get_notebooks (priv->note); g_list_foreach (tags, (GFunc) serialize_tags, priv->writer); xmlTextWriterEndElement (priv->writer); g_list_free (tags); // <open-on-startup> serialize_node (priv->writer, "open-on-startup", "False"); // <note> xmlTextWriterWriteRaw(priv->writer, BAD_CAST "\n "); xmlTextWriterEndElement(priv->writer); xmlFreeTextWriter(priv->writer); path = biji_item_get_uuid (BIJI_ITEM (priv->note)); retval = g_file_set_contents (path, (gchar*) priv->buf->content, -1, NULL); return retval; }