Class CustomXMLPart
Represents the custom XML part in the Word document.
Inheritance
System.Object
CustomXMLPart
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.Base.dll
Syntax
public class CustomXMLPart
Constructors
CustomXMLPart(WordDocument)
Initializes the Custom XML Part.
Declaration
public CustomXMLPart(WordDocument document)
Parameters
Type | Name | Description |
---|---|---|
WordDocument | document | A Word document. |
Properties
Id
Declaration
public string Id { get; }
Property Value
Type |
---|
System.String |
Methods
AddNode(CustomXMLNode, String, CustomXMLNodeType, String)
Adds a new node to the CustomXMLPart under the mentioned parent node.
Declaration
public void AddNode(CustomXMLNode customXmlNode, string name, CustomXMLNodeType nodeType, string nodeValue)
Parameters
Type | Name | Description |
---|---|---|
CustomXMLNode | customXmlNode | Represents the node under which this node should be added. If adding an attribute, the parameter denotes the element that the attribute should be added to. |
System.String | name | Represents the base name of the node to be added. |
CustomXMLNodeType | nodeType | Specifies the type of node to append. |
System.String | nodeValue | Used to set the value of the appended node for those nodes that allow text. |
Load(Stream)
Loads the CustomXMLPart from the XML string.
Declaration
public void Load(Stream xmlStream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | xmlStream | Specifies XML stream. |
Load(String)
Loads the CustomXMLPart from the given XML file path.
Declaration
public void Load(string filePath)
Parameters
Type | Name | Description |
---|---|---|
System.String | filePath | Specifies XML file path. |
Examples
The following code illustrates how to load XML file to CustomXMLPart.
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
//Add new XmlPart to the section
CustomXMLPart xmlPart = new CustomXMLPart(document);
//Load the xml code.
xmlPart.Load(@"F:\XmlFile.xml");
//Add new content control to the paragraph.
InlineContentControl control = paragraph.AppendInlineContentControl(ContentControlType.Text) as InlineContentControl;
control.ContentControlProperties.XmlMapping.SetMapping("/books/book/author", "", xmlPart);
//Select the single node.
CustomXMLNode node = xmlPart.SelectSingleNode(control.ContentControlProperties.XmlMapping.XPath);
//Append text to second paragraph.
control = paragraph.AppendInlineContentControl(ContentControlType.Text) as InlineContentControl;
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
'Add new XmlPart to the section
Dim xmlPart As New CustomXMLPart(document)
'Load the xml code.
xmlPart.Load(@"F:\XmlFile.xml");
'Append text to second paragraph.
control = TryCast(paragraph.AppendInlineContentControl(ContentControlType.Text), InlineContentControl)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
LoadXML(String)
Declaration
public void LoadXML(string xml)
Parameters
Type | Name | Description |
---|---|---|
System.String | xml |
SelectSingleNode(String)
Declaration
public CustomXMLNode SelectSingleNode(string xPath)
Parameters
Type | Name | Description |
---|---|---|
System.String | xPath |
Returns
Type |
---|
CustomXMLNode |