Xml 通过代码将节点插入现有XDocument
通过代码将节点插入现有XDocument 我使用WordprocessingDocument打开嵌入了xml模式的word文档,并通过XmlReader将其更改为XDocument XDocument如下所示Xml 通过代码将节点插入现有XDocument,xml,sharepoint-2010,Xml,Sharepoint 2010,通过代码将节点插入现有XDocument 我使用WordprocessingDocument打开嵌入了xml模式的word文档,并通过XmlReader将其更改为XDocument XDocument如下所示 <w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-
<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:body>
<w:customXml w:uri="http://tempuri.org/CustomSchema.xsd" w:element="UserDetails">
<w:p w:rsidR="00FE0E5B" w:rsidRDefault="00FE0E5B" />
<w:tbl>
<w:tblPr>
<w:tblStyle w:val="TableGrid" />
<w:tblW w:w="0" w:type="auto" />
<w:tblLook w:val="04A0" w:firstRow="1" w:lastRow="0" w:firstColumn="1" w:lastColumn="0" w:noHBand="0" w:noVBand="1" />
</w:tblPr>
<w:tblGrid>
<w:gridCol w:w="4788" />
<w:gridCol w:w="4788" />
</w:tblGrid>
<w:tr w:rsidR="0099743C" w:rsidTr="005B2968">
<w:tc>
<w:tcPr>
<w:tcW w:w="4788" w:type="dxa" />
</w:tcPr>
<w:p w:rsidR="0099743C" w:rsidRDefault="0099743C" w:rsidP="005B2968">
<w:r>
<w:t>User Name</w:t>
</w:r>
</w:p>
</w:tc>
<w:customXml w:uri="http://tempuri.org/CustomSchema.xsd" w:element="UserName">
<w:tc>
<w:tcPr>
<w:tcW w:w="4788" w:type="dxa" />
</w:tcPr>
<w:p w:rsidR="0099743C" w:rsidRDefault="0099743C" w:rsidP="005B2968">
<w:r>
<w:t xml:space="preserve"> </w:t>
</w:r>
</w:p>
</w:tc>
</w:customXml>
</w:tr>
//////////new node to be appended here
</w:tbl>
<w:p w:rsidR="00FE0E5B" w:rsidRDefault="00FE0E5B" />
<w:p w:rsidR="003978D7" w:rsidRDefault="009A3CD3" />
</w:customXml>
<w:sectPr w:rsidR="003978D7">
<w:pgSz w:w="12240" w:h="15840" />
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0" />
<w:cols w:space="720" />
<w:docGrid w:linePitch="360" />
</w:sectPr>
</w:body>
</w:document>
用户名
//////////要附加到此处的新节点
我想附加一个节点作为
<w:tr w:rsidR="007C2DEB" w14:paraId="14C244F6" w14:textId="77777777" w:rsidTr="005B2968" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:tc>
<w:tcPr>
<w:tcW w:w="4788" w:type="dxa" />
</w:tcPr>
<w:p w14:paraId="08782D94" w14:textId="06E7BC60" w:rsidR="007C2DEB" w:rsidRDefault="007C2DEB" w:rsidP="005B2968">
<w:r>
<w:t xml:space="preserve">Password </w:t>
</w:r>
</w:p>
</w:tc>
<w:customXml w:uri="http://tempuri.org/CustomSchema.xsd" w:element="Password">
<w:tc>
<w:tcPr>
<w:tcW w:w="4788" w:type="dxa" />
</w:tcPr>
<w:p w14:paraId="05792D0F" w14:textId="2205EB25" w:rsidR="007C2DEB" w:rsidRDefault="007C2DEB" w:rsidP="005B2968">
<w:r>
<w:t xml:space="preserve"> </w:t>
</w:r>
</w:p>
</w:tc>
<w:bookmarkStart w:id="0" w:name="_GoBack" w:displacedByCustomXml="next" />
<w:bookmarkEnd w:id="0" w:displacedByCustomXml="next" />
</w:customXml>
</w:tr>
暗语
就在“用户名”节点之后,然后保存合并的文档。如果您打算更改OOXML文档的内部结构,我可以恭敬地建议您查看专门为此目的设计的SDK:? 如果没有适当的限制和业务规则,我个人不会对非常复杂的XMl文档进行如此低级的操作。OpenXMLSDK就是这样做的。 有关如何操作Word文档中的自定义XML部分,请参见