create an XML file with wxXmlDocument
Biozic
bioziccc at free.fr
Tue Oct 30 05:44:22 PDT 2007
Éric Laly a écrit :
> Hello all,
>
> I'm trying to create this kind of XML file:
> <?xml version="1.0" encoding="utf8" ?>
> <CONFIGURATIONS>
> <DEFAUT>
> <CADRE taille="1,0" ></CADRE>
> <CADRE taille="0,4" ></CADRE>
> </DEFAUT>
> </CONFIGURATIONS>
>
> for this I'm using this code:
>
> wxXmlDocument configuration;
> wxXmlNode *root=new wxXmlNode(wxXML_ELEMENT_NODE,wxT("CONFIGURATIONS"));
> configuration.SetRoot(root);
>
> wxXmlNode *nomConf=new wxXmlNode (wxXML_ELEMENT_NODE,wxT("DEFAUT"));
> root->AddChild(nomConf);
>
> wxXmlNode *cadre1=new wxXmlNode (wxXML_ELEMENT_NODE,wxT("CADRE"));
> cadre1->AddProperty(wxT("taille"),wxT("1,0"));
> nomConf->AddChild(cadre1);
>
> wxXmlNode *cadre2=new wxXmlNode (wxXML_ELEMENT_NODE,wxT("CADRE"));
> cadre2->AddProperty(wxT("taille"),wxT("0,4"));
> nomConf->AddChild(cadre2);
>
> // on sauve le fichier de configuration
> if (!configuration.Save (wxT("config.xml"), 2))
> {
> wxLogWarning (wxT("Problème avec la création du fichier de
> configuration %s"),wxT ("config.xml"));
> }
>
> and I get this:
> <?xml version="1.0" encoding="utf-8"?>
> <CONFIGURATIONS>
> <DEFAUT>
> <CADRE taille="1,0"/>
> <CADRE taille="0,4"/>
> </DEFAUT>
> </CONFIGURATIONS>
>
> I'm certainly doing something wrong but after having searching
> mailing-list, forum and googling, I haven't found nothing...
>
> Is there a good soul on this ML ?
>
> Thanks in advance.
>
> Éric.
The XML you get is perfectly valid, isn't it? Nothing's wrong for me.
I guess you will get something looking like
<CADRE taille="1,0"> child node </CADRE>
only when you put at least a child node in CADRE.
Nicolas
More information about the wx-users
mailing list