Hi, I have written just simple Vala program, which should print out name
of root element

Without this line it works "<?xml version="1.0"
encoding="windows-1250"?>" (first line in RSS xml files)

OUTPUT

$ ./xml_parser rss.xml encoding error : input conversion failed due to
input error, bytes 0x88 0x6F 0x76 0x61
encoding error : input conversion failed due to input error, bytes 0x88
0x6F 0x76 0x61
I/O error : encoder error
rss.xml:60: parser error : Premature end of data in tag title line 60
      <title>Národná rada schválila povinnĂ© zverejĹ
                                                                ^
rss.xml:60: parser error : Premature end of data in tag item line 59
      <title>Národná rada schválila povinnĂ© zverejĹ
                                                                ^
rss.xml:60: parser error : Premature end of data in tag channel line 3
      <title>Národná rada schválila povinnĂ© zverejĹ
                                                                ^
rss.xml:60: parser error : Premature end of data in tag rss line 2
      <title>Národná rada schválila povinnĂ© zverejĹ
                                                                ^
Cannot open file

Attachment: rss.xml
Description: XML document

using Xml;

class xml_parser
{
	public void parse_file (string path)
	{
		Xml.Doc *file = Parser.parse_file (path);
		
		if (file == null)
		{
			stderr.printf ("Cannot open file");
			return;
		}
		
		Xml.Node *root = file->get_root_element ();
		
		if (root == null)
		{
			delete file;
			stderr.printf ("Xml file '%s' is empty", path);
			return;
		}
		
		stdout.printf ("Root node '%s'", root->name);
	}
}

int main (string[] args) {

    if (args.length < 2) {
        stderr.printf ("Argument required!\n");
        return 1;
    }

    // Initialisation, not instantiation since the parser is a static class
    Parser.init ();

    
    var sample = new xml_parser ();
    // Parse the file listed in the first passed argument
    sample.parse_file (args[1]);

    // Do the parser cleanup to free the used memory
    Parser.cleanup ();

    return 0;
}

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to