XML在WORD中插入图片的问题
以BASE64编码在WORDML中插入图片
最终形成的XML节点应如下:
<w:r >
<w:pict>
<v:shapetype id="_x0000_t75"/>
<w:binData w:name="wordml://02000001.jpg">/9j/4AAQSkAAAA==</w:binData>
<v:shape id="_x0000_i1026" type="#_x0000_t75" style="width:279.75pt;height:233.25pt" >
<v:imagedata src="wordml://02000001.jpg" o:title="picFreqSweep" />
</v:shape>
</w:pict>
</w:r>
问题,在我尝试如下插入节点时
XmlElement wpictElement = xml.CreateElement("w:pict");
wrElement.AppendChild(wpictElement );
其最终形成的XML节点会自动去除W:标记,只有PICT标记
因此改用
string nsWordML ="http://schemas.openxmlformats.org/wordprocessingml/2006/main";
XmlElement wpictElement = xml.CreateElement("w:pict", nsWordML);
wrElement.AppendChild(wpictElement );
这种方式生成的WORDML文件在每个节点和属性都加入了NAMESPACE
<w:r xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:pict>
<v:shapetype id="_x0000_t75" xmlns:v="http://schemas.openxmlformats.org/wordprocessingml/2006/main" />
<w:binData w:name="wordml://02000001.jpg">/9j/4AAAAAAA==</w:binData>
<v:shape id="_x0000_i1026" type="#_x0000_t75" style="width:279.75pt;height:233.25pt" xmlns:v="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<v:imagedata src="wordml://02000001.jpg" o:title="picFreqSweep" xmlns:o="http://schemas.openxmlformats.org/wordprocessingml/2006/main" />
</v:shape>
</w:pict>
</w:r>
这样生成的WORDML,在WORD中图片没有办法显示,但是去除NAMESPACE之后可以正常显示,请问,如何在编码的时候不加入NAMESPACE?