begin process at 2008 07 20 15:49:01
1 213 292 membres
207 nouveaux aujourd'hui
14 166 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

Sujet : [OpenXml] - les deux points dans les balises [ Système / Fichier & Disque ] (romagny13)

[OpenXml] - les deux points dans les balises le 19/04/2007 12:44:49

romagny13
Bonjour,

voila j'ai un problême lorsuqe je génére le fichier document.xml (OpenXml)
les balises sont de la forme <w:p> ou <w:r> par exemple

si j'utilise un XmlWriter > j'ai un message d'erreur
Caractère de nom non valide dans 'w:document'. Le caractère ':', valeur hexadécimale 0x3A, ne peut pas être inclus dans un nom.

si j'utilises un XmlDocument il enleve les w: et mes balises générées sont de la forme <p> ou <r> au lieu de <w:p> et <w:r>

comment faire pour conserver la balise telle qu'il faut la générer (avec donc w: )  ?
(que ce soit avec un XmlWriter ou XmlDocument)

Re : [OpenXml] - les deux points dans les balises le 19/04/2007 12:54:42

romagny13
Voila un exemple de code cela vous aidera peut etre à m'aider :p lol

// 1 avec XmlDocument

using (System.IO.Stream oStream = oPackagePart.GetStream())

{

System.Xml.

XmlDocument oXmlDocument;

oXmlDocument =

new System.Xml.XmlDocument();

System.Xml.

XmlElement oXmlElementDocument = oXmlDocument.CreateElement("w:document");

System.Xml.

XmlElement oXmlElementBody = oXmlDocument.CreateElement("w:body");

System.Xml.

XmlElement oXmlElementParagraph = oXmlDocument.CreateElement("w:p");

System.Xml.

XmlElement oXmlElementRun = oXmlDocument.CreateElement("w:r");

System.Xml.

XmlElement oXmlElementText = oXmlDocument.CreateElement("w:t");

System.Xml.

XmlText oXmlText = oXmlDocument.CreateTextNode("ouiiiiiiiiiii");

oXmlDocument.AppendChild(oXmlElementDocument);

oXmlElementDocument.AppendChild(oXmlElementBody);

oXmlElementBody.AppendChild(oXmlElementParagraph);

oXmlElementParagraph.AppendChild(oXmlElementRun);

oXmlElementRun.AppendChild(oXmlElementText);

oXmlElementText.AppendChild(oXmlText);

oXmlDocument.Save(oStream);

oPackage.Flush();

oPackage.Close();

}

 

//2 avec XmlWriter

System.Xml.

XmlWriter oXmlWriter;

System.Xml.

XmlWriterSettings oXmlWriterSettings;

 

oXmlWriterSettings =

new System.Xml.XmlWriterSettings();

oXmlWriterSettings.Indent =

true;

oXmlWriterSettings.Encoding = System.Text.

Encoding.UTF32;

oXmlWriter = System.Xml.

XmlWriter.Create(oPackagePart.GetStream(), oXmlWriterSettings);

oXmlWriter.WriteStartElement(

"w:document");

oXmlWriter.WriteStartElement(

"w:body");

oXmlWriter.WriteStartElement(

"w:p");

oXmlWriter.WriteStartElement(

"w:r");

oXmlWriter.WriteElementString(

"w:t", "ouiiiiiiiiiiiiiiii");

oXmlWriter.WriteEndElement();

oXmlWriter.WriteEndElement();

oXmlWriter.WriteEndElement();

oXmlWriter.WriteEndElement();

// root

oXmlWriter.Close();


Re : [OpenXml] - les deux points dans les balises le 19/04/2007 13:30:04

romagny13
Réponse acceptée !
Bon j'ai peut être trouvé en fait apparemment il faut obligatoirement indiquer le namespace pour chaque element :


System.IO.Packaging.

PackagePart oPackagePart = oPackage.CreatePart(oUri, "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml");

string WordprocessingML = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

//// 1 avec XmlDocument

using (System.IO.Stream oStream = oPackagePart.GetStream())

{

System.Xml.

XmlDocument oXmlDocument;

oXmlDocument =

new System.Xml.XmlDocument();

System.Xml.

XmlElement oXmlElementDocument = oXmlDocument.CreateElement("w:document", WordprocessingML);

System.Xml.

XmlElement oXmlElementBody = oXmlDocument.CreateElement("w:body", WordprocessingML);

System.Xml.

XmlElement oXmlElementParagraph = oXmlDocument.CreateElement("w:p", WordprocessingML);

System.Xml.

XmlElement oXmlElementRun = oXmlDocument.CreateElement("w:r", WordprocessingML);

System.Xml.

XmlElement oXmlElementText = oXmlDocument.CreateElement("w:t", WordprocessingML);

System.Xml.

XmlText oXmlText = oXmlDocument.CreateTextNode("ouiiiiiiiiiii");

oXmlDocument.AppendChild(oXmlElementDocument);

oXmlElementDocument.AppendChild(oXmlElementBody);

oXmlElementBody.AppendChild(oXmlElementParagraph);

oXmlElementParagraph.AppendChild(oXmlElementRun);

oXmlElementRun.AppendChild(oXmlElementText);

oXmlElementText.AppendChild(oXmlText);

oXmlDocument.Save(oStream);

oPackage.Flush();

oPackage.Close();

}



Classé sous : points, document, forme, balises, openxml

Participer à cet échange

Pub



Appels d'offres

Dessins techniques
Budget : 60€
Animation Flash - Doma...
Budget : 370€
Application flash medi...
Budget : 1 000€

CalendriCode

Juillet 2008
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Téléchargements

Logiciels à télécharger sur le même thème :

Boutique

Boutique de goodies CodeS-SourceS