Textboxs vers du xml

alphacrash Messages postés 55 Date d'inscription jeudi 7 novembre 2002 Statut Membre Dernière intervention 17 août 2012 - 2 juil. 2008 à 14:51
cs_Bidou Messages postés 5487 Date d'inscription dimanche 4 août 2002 Statut Membre Dernière intervention 20 juin 2013 - 2 juil. 2008 à 21:46
Voilà, j'ai un soucis de créationd e fichier XML.
En clair, je veux sauver dans un fichier XML des données issues de textBox, problème, j'ai une exception générée:
An error occurred while parsing EntityName. Line 18, position 85.

Je pense que ça vient d'un caractère special ou bien un caractère qui passe mal.

 public int i = 1;

        public string posts_head = @"<?xml version='1.0' encoding='UTF-8'?>
<rss version='2.0'
    xmlns:content='http://purl.org/rss/1.0/modules/content/'
    xmlns:wfw='http://wellformedweb.org/CommentAPI/'
    xmlns:dc='http://purl.org/dc/elements/1.1/'
    xmlns:wp='http://wordpress.org/export/1.0/'
>

<channel>
  
    <description>Just another WordPress weblog</description>
    Tue, 24 Jun 2008 14:22:19 +0000

    <generator>http://wordpress.org/?v=2.5.1</generator>
    <language>en</language>
    <wp:wxr_version>1.0</wp:wxr_version>
   
           
            public string posts_xml = null;
        public string posts_footer = "</channel></rss>";
        public string result_xml = null;
        private void timer1_Tick(object sender, EventArgs e)
        {

            if (i != 2)
            {
                show_infos_article(i);
              
       
               posts_xml = posts_xml + " <title>" + textBox5.Text + "</title><link>http://127.0.0.1/buzzpublic/" + textBox5.Text.Replace(" ", "-") + "/</link><dc:creator><![CDATA[" + textBox8.Text + "]]></dc:creator><category><![CDATA[" + textBox23.Text + "]]></category><category domain='category' nicename='" + textBox23.Text + "'><![CDATA[" + textBox23.Text + "]]></category>" + parse_tags(textBox4.Text) + "<description></description><content:encoded><![CDATA[" + textBox2.Text + "]]></content:encoded><wp:post_date>" + textBox9.Text.Replace("/", "-") + "</wp:post_date><wp:post_date_gmt>" + textBox9.Text.Replace("/", "-") + "</wp:post_date_gmt><wp:comment_status>open</wp:comment_status><wp:ping_status>open</wp:ping_status><wp:post_name>" + textBox5.Text.Replace(" ", "-") + "</wp:post_name><wp:status>publish</wp:status><wp:post_parent>0</wp:post_parent><wp:menu_order>0</wp:menu_order><wp:post_type>post</wp:post_type><wp:post_password></wp:post_password><wp:postmeta><wp:meta_key>_edit_lock</wp:meta_key><wp:meta_value>1213616767</wp:meta_value></wp:postmeta><wp:postmeta><wp:meta_key>_edit_last</wp:meta_key><wp:meta_value>1</wp:meta_value></wp:postmeta><wp:postmeta><wp:meta_key>thumb</wp:meta_key><wp:meta_value>" + pictureBox1.ImageLocation + "</wp:meta_value></wp:postmeta><wp:postmeta><wp:meta_key>descriptif</wp:meta_key><wp:meta_value>" + textBox6.Text + "</wp:meta_value></wp:postmeta><wp:postmeta><wp:meta_key>sources</wp:meta_key><wp:meta_value>" + parse_sources(textBox7.Text) + "</wp:meta_value></wp:postmeta>" + show_comments(i) + " ";
            
                   
                i++;
                textBox3.Text = i.ToString();

            }
            else{
                timer1.Enabled =false;
            XmlDocument fichierXML = new XmlDocument();
            result_xml = posts_head + posts_xml + posts_footer;
           
                fichierXML.LoadXml(result_xml);
            fichierXML.Save(@"c:\ex.xml");
            }
        }

Merci à tout le monde !

Coding is not a crime!

1 réponse

cs_Bidou Messages postés 5487 Date d'inscription dimanche 4 août 2002 Statut Membre Dernière intervention 20 juin 2013 61
2 juil. 2008 à 21:46
Salut,
Ne jamais concaténer des strings comme tu l'as fait! Utiliser StringBuilder à la place.
Ensuite, je ne suis pas certain que ça soit la meilleure façon de faire que de générer un immense string pour le fichier, pourquoi ne pas plutôt utiliser les classes misent à disposition pour faire ce travail? (XmlDocument, XmlWriter, ....)

<hr />
-My Blog-
0
Rejoignez-nous