TextWriter
Object Hierarchy:
Xml.TextWriter
Xml.TextWriter
Xml.TextWriter
Description:
[ Compact ] [ CCode ( cname = "xmlTextWriter" , free_function = "xmlFreeTextWriter" ) ]public class TextWriter
Example: TextWriter:
private inline void ret_to_ex (int errc) throws FileError { if (errc < 0 ) { throw new FileError.FAILED ("Failed" ); } }public class Books : Object { private SList<Book> books; public Books (owned SList<Book> books) { this .books = (owned ) books; } public void write (Xml.TextWriter writer) throws FileError { ret_to_ex (writer.start_element ("books" )); foreach (Book book in books) { book.write (writer); } ret_to_ex (writer.end_element ()); } }public class Book : Object { public string author { private set ; get ; } public string title { private set ; get ; } public int64 id { private set ; get ; } public Book (int64 id, string author, string title) { this .author = author; this .title = title; this .id = id; } public void write (Xml.TextWriter writer) throws FileError { ret_to_ex (writer.start_element ("book" )); ret_to_ex (writer.write_attribute ("id" , id.to_string ())); ret_to_ex (writer.start_element ("title" )); ret_to_ex (writer.write_string (title)); ret_to_ex (writer.end_element ()); ret_to_ex (writer.start_element ("author" )); ret_to_ex (writer.write_string (author)); ret_to_ex (writer.end_element ()); ret_to_ex (writer.end_element ()); } }public static int main (string [] args) { SList<Book> book_list = new SList<Book> (); book_list.prepend (new Book (2 , "Franz Kafka" , "The Stoker" )); book_list.prepend (new Book (1 , "Stefan Zweig" , "The Royal Game" )); Books books = new Books ((owned ) book_list); Xml.TextWriter writer = new Xml.TextWriter.filename ("my-books.xml" , false ); if (writer == null ) { print ("Error: Xml.TextWriter.filename () == null \n " ); return 0 ; } try { ret_to_ex (writer.start_document ("1.0" , "utf-8" )); writer.set_indent (true ); books.write (writer); ret_to_ex (writer.flush ()); } catch (Error e) { print ("Error: %s \n " , e.message); } return 0 ; }
valac --pkg libxml-2.0 xml-text-writer.vala
Content:
Creation methods:
Methods:
public int end_attribute ()
public int end_cdata ()
public int end_comment ()
public int end_document ()
public int end_dtd ()
public int end_dtd_attlist ()
public int end_dtd_element ()
public int end_dtd_entity ()
public int end_element ()
public int flush ()
public int format_attribute (string name, string format, ...)
public int format_attribute_ns (string prefix, string name, string namespaceURI, string format, ...)
public int format_cdata (string format, ...)
public int format_comment (string format, ...)
public int format_element (string name, string format, ...)
public int format_element_ns (string prefix, string name, string namespaceURI, string format, ...)
public int format_string (string format, ...)
public int set_indent (bool indent)
public int set_indent_string (string str)
public int start_attribute (string name)
public int start_attribute_ns (string ? prefix, string name, string ? namespaceURI)
public int start_cdata ()
public int start_comment ()
public int start_document (string ? version = null , string ? encoding = null , string ? standalone = null )
public int start_dtd (string name, string ? pubid, string ? sysid)
public int start_dtd_attlist (string name)
public int start_dtd_element (string name)
public int start_dtd_entity (bool pe, string name)
public int start_element (string name)
public int start_element_ns (string prefix, string name, string ? namespaceURI)
public int write_attribute (string name, string content)
public int write_attribute_ns (string ? prefix, string name, string ? namespaceURI, string content)
public int write_base64 (void * data, int start, int length)
public int write_cdata (string content)
public int write_comment (string content)
public int write_document_type (string name, string ? pubid, string ? sysid, string ? subset)
public int write_dtd (string name, string ? pubid, string ? sysid, string ? subset)
public int write_dtd_attlist (string name, string content)
public int write_dtd_element (string name, string content)
public int write_dtd_entity (bool pe, string name, string ? pubid, string ? sysid, string ndataid, string content)
public int write_dtd_external_entity (bool pe, string name, string ? pubid, string ? sysid, string ndataid)
public int write_dtd_external_entity_contents (string ? pubid, string ? sysid, string ndataid)
public int write_dtd_internal_entity (bool pe, string name, string content)
public int write_dtd_notation (string name, string ? pubid, string ? sysid)
public int write_element (string name, string content)
public int write_element_ns (string prefix, string name, string namespaceURI, string content)
public int write_pi (string target, string content)
public int write_string (string content)