C# Word、VSTO、OpenXml—将XML插入段落对象
我使用以下代码将xml(openxml)注入Word中段落的范围。问题是我收到一条错误消息,指出“无法将XML标记插入指定位置” c#代码: 要注入的XML:C# Word、VSTO、OpenXml—将XML插入段落对象,c#,ms-word,vsto,openxml,openxml-sdk,C#,Ms Word,Vsto,Openxml,Openxml Sdk,我使用以下代码将xml(openxml)注入Word中段落的范围。问题是我收到一条错误消息,指出“无法将XML标记插入指定位置” c#代码: 要注入的XML: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?mso-application progid="Word.Document"?> <pkg:package xmlns:pkg="http://schemas.microsoft.com/off
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?mso-application progid="Word.Document"?>
<pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 wp14">
<w:p>
<w:r>
<w:t xml:space="preserve">(a) Costs and Expenses</w:t>
</w:r>
<w:del w:id="33350" w:author="Exemplify">
<w:r>
<w:delText xml:space="preserve">. </w:delText>
</w:r>
</w:del>
<w:r>
<w:t xml:space="preserve"> The</w:t>
</w:r>
<w:commentRangeStart w:id="33351" />
<w:del w:id="33352" w:author="Exemplify">
<w:r>
<w:delText xml:space="preserve"> Borrower</w:delText>
</w:r>
</w:del>
<w:commentRangeEnd w:id="33351" />
<w:r>
<w:commentReference w:id="33351" />
</w:r>
<w:r>
<w:t xml:space="preserve"> shall pay (i) all reasonable out-of-pocket expenses incurred by the Administrative Agent and its Affiliates</w:t>
</w:r>
<w:del w:id="33353" w:author="Exemplify">
<w:r>
<w:delText xml:space="preserve">, </w:delText>
</w:r>
</w:del>
<w:ins w:id="33354" w:author="Exemplify">
<w:r>
<w:t xml:space="preserve"> (</w:t>
</w:r>
</w:ins>
<w:r>
<w:t xml:space="preserve">.</w:t>
</w:r>
</w:p>
</w:document>
</pkg:package>
(a) 成本和费用
.
这个
借贷者
应支付(i)管理代理及其附属公司产生的所有合理的现付费用
,
(
.
要使用InsertXML,XML必须是一个完整、有效的Word 2003 WordProcessingML文档,或者是一个完整、有效的OPC格式的Open Office XML文档。目前,您拥有的XML不是这两种文档中的任何一种
要成为有效的平面OPC包,包必须包含部件,并定义必要的部件关系
要成为有效的Word 2003 XML文档,名称空间声明需要不同,文档元素需要不同
<w:wordDocument>
在这里面你需要一个
<w:body>
元素。我怀疑您拥有的某些元素对于该XML词汇表无效(您可以自己检查),但例如,删除了某些元素和属性的以下XML应该是正确的:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?mso-application progid="Word.Document"?>
<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
<w:body>
<w:p>
<w:r>
<w:t>(a) Costs and Expenses</w:t>
</w:r>
<w:r>
<w:t> The</w:t>
</w:r>
<w:r>
</w:r>
<w:r>
<w:t> shall pay (i) all reasonable out-of-pocket expenses incurred by the Administrative Agent and its Affiliates</w:t>
</w:r>
<w:r>
<w:t>.</w:t>
</w:r>
</w:p>
</w:body>
</w:wordDocument>
(a) 成本和费用
这个
应支付(i)管理代理及其附属公司产生的所有合理的现付费用
.
对于Word 2007和更高版本的XML,所有内容都需要位于包中的一个部分中,包必须定义一些关系。在这种情况下,可以执行以下操作(您只需要XML中实际引用的命名空间定义):
(a) 成本和费用
.
这个
借贷者
应支付(i)管理代理及其附属公司产生的所有合理的现付费用
,
(
.
我省略了xml:space=“preserve”属性——您可能需要它们
<w:r>
<w:commentReference w:id="33351" />
</w:r>
这将导致失败。我猜这是因为它实际上引用了一个Id不存在的注释。要使用InsertXML,XML必须是一个完整、有效的Word 2003 WordProcessingML文档,或者是一个完整、有效的OPC格式的Open Office XML文档。目前,您拥有的XML不是这两种格式中的任何一种 要成为有效的平面OPC包,包必须包含部件,并定义必要的部件关系 要成为有效的Word 2003 XML文档,名称空间声明需要不同,文档元素需要不同
<w:wordDocument>
在这里面你需要一个
<w:body>
元素。我怀疑您拥有的某些元素对于该XML词汇表无效(您可以自己检查),但例如,删除了某些元素和属性的以下XML应该是正确的:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?mso-application progid="Word.Document"?>
<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
<w:body>
<w:p>
<w:r>
<w:t>(a) Costs and Expenses</w:t>
</w:r>
<w:r>
<w:t> The</w:t>
</w:r>
<w:r>
</w:r>
<w:r>
<w:t> shall pay (i) all reasonable out-of-pocket expenses incurred by the Administrative Agent and its Affiliates</w:t>
</w:r>
<w:r>
<w:t>.</w:t>
</w:r>
</w:p>
</w:body>
</w:wordDocument>
(a) 成本和费用
这个
应支付(i)管理代理及其附属公司产生的所有合理的现付费用
.
对于Word 2007和更高版本的XML,所有内容都需要位于包中的一个部分中,包必须定义一些关系。在这种情况下,可以执行以下操作(您只需要XML中实际引用的命名空间定义):
(a) 成本和费用
.
这个
借贷者
应支付(i)管理代理及其附属公司产生的所有合理的现付费用
,
(
.
我省略了xml:space=“preserve”属性——您可能需要它们
<w:r>
<w:commentReference w:id="33351" />
</w:r>
这将导致失败。我猜这是因为它实际上引用了一个Id不存在的评论。谢谢,@bibadia,你救了我的命!:)谢谢,@bibadia,你救了我的命!:)