Sérialization XML avec préfixe
Bonjour,
Je souhaite sérialiser une classe en utilisant XmlSerializer avec XMLElement.
J'ai besoin de mettre des préfixes sur les balises pour être conforme avec le format attendu par l'application cliente mais les ":" sont remplacés par leur code ascii (_x003A_)
Voici mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
[XmlRoot("rsm:CrossIndustryInvoice")]
public class CrossIndustryInvoice
{
[XmlElement("rsm:ExchangedDocumentContext")]
public ExchangedDocumentContext exchangedDocumentContext;
public CrossIndustryInvoice()
{
exchangedDocumentContext = new ExchangedDocumentContext();
}
}
static void Main(string[] args)
{
CrossIndustryInvoice crossIndustryInvoice = new CrossIndustryInvoice();
XmlSerializer xs = new XmlSerializer(typeof(CrossIndustryInvoice));
using (StreamWriter wr = new StreamWriter("CrossIndustryInvoice.xml"))
{
xs.Serialize(wr, crossIndustryInvoice);
}
} |
Le résultat attendu est
Code:
1 2 3 4 5 6
|
<?xml version="1.0" encoding="utf-8"?>
<rsm:CrossIndustryInvoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<rsm:ExchangedDocumentContext>
</rsm:ExchangedDocumentContext>
</rsm:CrossIndustryInvoice> |
mais j'obtiens
Code:
1 2 3 4 5 6
|
<?xml version="1.0" encoding="utf-8"?>
<rsm_x003A_CrossIndustryInvoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<rsm_x003A_ExchangedDocumentContext>
</rsm_x003A_ExchangedDocumentContext>
</rsm_x003A_CrossIndustryInvoice> |
Existe-t-il un caractère d'échappement pour forcer le ":"?
La seule solution est-elle de ré-ouvrir le fichier après création pour remplacer les caractères?