2010-03-30 17 views
1

Aide requise.Erreur lors de la tentative d'insertion de l'image dans wordML

Je reçois cette erreur

{"The xml has invalid content and cannot be constructed as an element.\r\nParameter name: outerXml"} 

en passant construit xml pour le constructeur DocumentFormat.OpenXml.Office.Drawing.Drawing() comme celui-ci

DocumentFormat.OpenXml.Office.Drawing.Drawing d = new DocumentFormat.OpenXml.Office.Drawing.Drawing(img); 

Voici le xml qui est passé dans

<w:drawing xmlns:w="http://schemas.openxmlformats.org/drawingml/2006/main"> 
       <wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251658240" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"> 
        <wp:simplePos x="0" y="0"/> 
        <wp:positionH relativeFrom="column"> 
        <wp:align>right</wp:align> 
        </wp:positionH> 
        <wp:positionV relativeFrom="paragraph"> 
        <wp:align>top</wp:align> 
        </wp:positionV> 
        <wp:extent cx="400" cy="400"/> 
        <wp:effectExtent l="19050" t="0" r="0" b="0"/> 
        <wp:wrapSquare wrapText="bothSides"/> 
        <wp:docPr id="1" name="image"/> 
        <wp:cNvGraphicFramePr> 
        <a:graphicFrameLocks noChangeAspect="1" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/> 
        </wp:cNvGraphicFramePr> 
        <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"> 
        <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"> 
         <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"> 
         <pic:nvPicPr> 
          <pic:cNvPr id="0" name="image"/> 
          <pic:cNvPicPr> 
          <a:picLocks noChangeAspect="1" noChangeArrowheads="1"/> 
          </pic:cNvPicPr> 
         </pic:nvPicPr> 
         <pic:blipFill> 
          <a:blip r:embed="rIdImg4" cstate="print" xmlns:r="http://schemas.openxmlformats.org/drawingml/2006/relationships"/> 
          <a:stretch> 
          <a:fillRect/> 
          </a:stretch> 
         </pic:blipFill> 
         <pic:spPr bwMode="auto"> 
          <a:xfrm> 
          <a:off x="0" y="0"/> 
          <a:ext cx="400" cy="400"/> 
          </a:xfrm> 
          <a:prstGeom prst="rect"> 
          <a:avLst/> 
          </a:prstGeom> 
          <a:noFill/> 
          <a:ln w="9525"> 
          <a:noFill/> 
          <a:miter lim="800000"/> 
          <a:headEnd/> 
          <a:tailEnd/> 
          </a:ln> 
         </pic:spPr> 
         </pic:pic> 
        </a:graphicData> 
        </a:graphic> 
       </wp:anchor> 
       </w:drawing> 

Merci, Kiru

Répondre

2

L'élément que vous créez à partir du fichier XML se trouve dans l'espace de noms Dessin. (Souvent vu en utilisant le "a:" préfixe.) Lors de la création de ces éléments à partir de chaînes OuterXml le nœud racine doit correspondre avec le type de l'objet en cours de création. (Dans ce cas un DocumentFormat.OpenXml.Office.Drawing.Drawing). Le problème ici est que le nœud racine XML est pour un élément différent.

Essayez de créer un objet DocumentFormat.OpenXml.WordProcessing.Drawing(): http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.drawing.aspx

Il peut être difficile de trouver le bon niveau auquel pour injecter le DrawingML. Sortez l'outil OpenXmlSDK pour voir ce qui est valide sous quels noeuds. Bonne chance!