public class CustomXmlPartCollection
You do not normally need to create instances of this class. You can access custom XML data
stored in a document via the
Example:
Shows how to create structured document tag with a custom XML data.Document doc = new Document(); // Construct an XML part that contains data and add it to the document's collection // Once the "Developer" tab in Mircosoft Word is enabled, // we can find elements from this collection as well as a couple defaults in the "XML Mapping Pane" String xmlPartId = UUID.randomUUID().toString(); String xmlPartContent = "<root><text>Hello, World!</text></root>"; CustomXmlPart xmlPart = doc.getCustomXmlParts().add(xmlPartId, xmlPartContent); // The data we entered resides in these variables Assert.assertEquals(xmlPart.getData(), xmlPartContent.getBytes()); Assert.assertEquals(xmlPart.getId(), xmlPartId); // XML parts can be referenced by collection index or GUID Assert.assertEquals(doc.getCustomXmlParts().get(0), xmlPart); Assert.assertEquals(doc.getCustomXmlParts().getById(xmlPartId), xmlPart); // Once the part is created, we can add XML schema associations like this xmlPart.getSchemas().add("http://www.w3.org/2001/XMLSchema"); // We can also clone parts and insert them into the collection directly CustomXmlPart xmlPartClone = xmlPart.deepClone(); xmlPartClone.setId(UUID.randomUUID().toString()); doc.getCustomXmlParts().add(xmlPartClone); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 2); // Iterate through collection with an enumerator and print the contents of each part Iterator<CustomXmlPart> enumerator = doc.getCustomXmlParts().iterator(); int index = 0; while (enumerator.hasNext()) { CustomXmlPart customXmlPart = enumerator.next(); System.out.println(MessageFormat.format("XML part index {0}, ID: {1}", index, customXmlPart.getId())); System.out.println(MessageFormat.format("\tContent: {0}", customXmlPart.getData())); index++; } // XML parts can be removed by index doc.getCustomXmlParts().removeAt(1); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 1); // The XML part collection itself can be cloned also CustomXmlPartCollection customXmlParts = doc.getCustomXmlParts().deepClone(); // And all elements can be cleared like this customXmlParts.clear(); // Create a StructuredDocumentTag that will display the contents of our part, // insert it into the document and save the document StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.PLAIN_TEXT, MarkupLevel.BLOCK); sdt.getXmlMapping().setMapping(xmlPart, "/root[1]/text[1]", ""); doc.getFirstSection().getBody().appendChild(sdt); doc.save(getArtifactsDir() + "StructuredDocumentTag.CustomXml.docx");
Constructor Summary |
---|
Property Getters/Setters Summary | ||
---|---|---|
int | getCount() | |
Gets the number of elements contained in the collection.
|
||
CustomXmlPart | get(int index) | |
void | set(intindex, CustomXmlPart value) | |
Gets or sets an item at the specified index. |
Method Summary | ||
---|---|---|
void | add(CustomXmlPart part) | |
Adds an item to the collection.
|
||
CustomXmlPart | add(java.lang.String id, java.lang.String xml) | |
Creates a new XML part with the specified XML and adds it to the collection.
|
||
void | clear() | |
Removes all elements from the collection.
|
||
CustomXmlPartCollection | deepClone() | |
Makes a deep copy of this collection and its items.
|
||
CustomXmlPart | getById(java.lang.String id) | |
Finds and returns a custom XML part by its identifier.
|
||
java.util.Iterator<CustomXmlPart> | iterator() | |
Returns an iterator object that can be used to iterate over all items in the collection.
|
||
void | removeAt(int index) | |
Removes an item at the specified index.
|
public int getCount()
Example:
Shows how to create structured document tag with a custom XML data.Document doc = new Document(); // Construct an XML part that contains data and add it to the document's collection // Once the "Developer" tab in Mircosoft Word is enabled, // we can find elements from this collection as well as a couple defaults in the "XML Mapping Pane" String xmlPartId = UUID.randomUUID().toString(); String xmlPartContent = "<root><text>Hello, World!</text></root>"; CustomXmlPart xmlPart = doc.getCustomXmlParts().add(xmlPartId, xmlPartContent); // The data we entered resides in these variables Assert.assertEquals(xmlPart.getData(), xmlPartContent.getBytes()); Assert.assertEquals(xmlPart.getId(), xmlPartId); // XML parts can be referenced by collection index or GUID Assert.assertEquals(doc.getCustomXmlParts().get(0), xmlPart); Assert.assertEquals(doc.getCustomXmlParts().getById(xmlPartId), xmlPart); // Once the part is created, we can add XML schema associations like this xmlPart.getSchemas().add("http://www.w3.org/2001/XMLSchema"); // We can also clone parts and insert them into the collection directly CustomXmlPart xmlPartClone = xmlPart.deepClone(); xmlPartClone.setId(UUID.randomUUID().toString()); doc.getCustomXmlParts().add(xmlPartClone); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 2); // Iterate through collection with an enumerator and print the contents of each part Iterator<CustomXmlPart> enumerator = doc.getCustomXmlParts().iterator(); int index = 0; while (enumerator.hasNext()) { CustomXmlPart customXmlPart = enumerator.next(); System.out.println(MessageFormat.format("XML part index {0}, ID: {1}", index, customXmlPart.getId())); System.out.println(MessageFormat.format("\tContent: {0}", customXmlPart.getData())); index++; } // XML parts can be removed by index doc.getCustomXmlParts().removeAt(1); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 1); // The XML part collection itself can be cloned also CustomXmlPartCollection customXmlParts = doc.getCustomXmlParts().deepClone(); // And all elements can be cleared like this customXmlParts.clear(); // Create a StructuredDocumentTag that will display the contents of our part, // insert it into the document and save the document StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.PLAIN_TEXT, MarkupLevel.BLOCK); sdt.getXmlMapping().setMapping(xmlPart, "/root[1]/text[1]", ""); doc.getFirstSection().getBody().appendChild(sdt); doc.save(getArtifactsDir() + "StructuredDocumentTag.CustomXml.docx");
public CustomXmlPart get(int index) / public void set(int index, CustomXmlPart value)
index
- Zero-based index of the item.Example:
Shows how to create structured document tag with a custom XML data.Document doc = new Document(); // Construct an XML part that contains data and add it to the document's collection // Once the "Developer" tab in Mircosoft Word is enabled, // we can find elements from this collection as well as a couple defaults in the "XML Mapping Pane" String xmlPartId = UUID.randomUUID().toString(); String xmlPartContent = "<root><text>Hello, World!</text></root>"; CustomXmlPart xmlPart = doc.getCustomXmlParts().add(xmlPartId, xmlPartContent); // The data we entered resides in these variables Assert.assertEquals(xmlPart.getData(), xmlPartContent.getBytes()); Assert.assertEquals(xmlPart.getId(), xmlPartId); // XML parts can be referenced by collection index or GUID Assert.assertEquals(doc.getCustomXmlParts().get(0), xmlPart); Assert.assertEquals(doc.getCustomXmlParts().getById(xmlPartId), xmlPart); // Once the part is created, we can add XML schema associations like this xmlPart.getSchemas().add("http://www.w3.org/2001/XMLSchema"); // We can also clone parts and insert them into the collection directly CustomXmlPart xmlPartClone = xmlPart.deepClone(); xmlPartClone.setId(UUID.randomUUID().toString()); doc.getCustomXmlParts().add(xmlPartClone); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 2); // Iterate through collection with an enumerator and print the contents of each part Iterator<CustomXmlPart> enumerator = doc.getCustomXmlParts().iterator(); int index = 0; while (enumerator.hasNext()) { CustomXmlPart customXmlPart = enumerator.next(); System.out.println(MessageFormat.format("XML part index {0}, ID: {1}", index, customXmlPart.getId())); System.out.println(MessageFormat.format("\tContent: {0}", customXmlPart.getData())); index++; } // XML parts can be removed by index doc.getCustomXmlParts().removeAt(1); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 1); // The XML part collection itself can be cloned also CustomXmlPartCollection customXmlParts = doc.getCustomXmlParts().deepClone(); // And all elements can be cleared like this customXmlParts.clear(); // Create a StructuredDocumentTag that will display the contents of our part, // insert it into the document and save the document StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.PLAIN_TEXT, MarkupLevel.BLOCK); sdt.getXmlMapping().setMapping(xmlPart, "/root[1]/text[1]", ""); doc.getFirstSection().getBody().appendChild(sdt); doc.save(getArtifactsDir() + "StructuredDocumentTag.CustomXml.docx");
public void add(CustomXmlPart part)
part
- The custom XML part to add.Example:
Shows how to create structured document tag with a custom XML data.Document doc = new Document(); // Construct an XML part that contains data and add it to the document's collection // Once the "Developer" tab in Mircosoft Word is enabled, // we can find elements from this collection as well as a couple defaults in the "XML Mapping Pane" String xmlPartId = UUID.randomUUID().toString(); String xmlPartContent = "<root><text>Hello, World!</text></root>"; CustomXmlPart xmlPart = doc.getCustomXmlParts().add(xmlPartId, xmlPartContent); // The data we entered resides in these variables Assert.assertEquals(xmlPart.getData(), xmlPartContent.getBytes()); Assert.assertEquals(xmlPart.getId(), xmlPartId); // XML parts can be referenced by collection index or GUID Assert.assertEquals(doc.getCustomXmlParts().get(0), xmlPart); Assert.assertEquals(doc.getCustomXmlParts().getById(xmlPartId), xmlPart); // Once the part is created, we can add XML schema associations like this xmlPart.getSchemas().add("http://www.w3.org/2001/XMLSchema"); // We can also clone parts and insert them into the collection directly CustomXmlPart xmlPartClone = xmlPart.deepClone(); xmlPartClone.setId(UUID.randomUUID().toString()); doc.getCustomXmlParts().add(xmlPartClone); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 2); // Iterate through collection with an enumerator and print the contents of each part Iterator<CustomXmlPart> enumerator = doc.getCustomXmlParts().iterator(); int index = 0; while (enumerator.hasNext()) { CustomXmlPart customXmlPart = enumerator.next(); System.out.println(MessageFormat.format("XML part index {0}, ID: {1}", index, customXmlPart.getId())); System.out.println(MessageFormat.format("\tContent: {0}", customXmlPart.getData())); index++; } // XML parts can be removed by index doc.getCustomXmlParts().removeAt(1); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 1); // The XML part collection itself can be cloned also CustomXmlPartCollection customXmlParts = doc.getCustomXmlParts().deepClone(); // And all elements can be cleared like this customXmlParts.clear(); // Create a StructuredDocumentTag that will display the contents of our part, // insert it into the document and save the document StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.PLAIN_TEXT, MarkupLevel.BLOCK); sdt.getXmlMapping().setMapping(xmlPart, "/root[1]/text[1]", ""); doc.getFirstSection().getBody().appendChild(sdt); doc.save(getArtifactsDir() + "StructuredDocumentTag.CustomXml.docx");
public CustomXmlPart add(java.lang.String id, java.lang.String xml)
id
- Identifier of a new custom XML part.xml
- XML data of the part.Example:
Shows how to create structured document tag with a custom XML data.Document doc = new Document(); // Construct an XML part that contains data and add it to the document's collection // Once the "Developer" tab in Mircosoft Word is enabled, // we can find elements from this collection as well as a couple defaults in the "XML Mapping Pane" String xmlPartId = UUID.randomUUID().toString(); String xmlPartContent = "<root><text>Hello, World!</text></root>"; CustomXmlPart xmlPart = doc.getCustomXmlParts().add(xmlPartId, xmlPartContent); // The data we entered resides in these variables Assert.assertEquals(xmlPart.getData(), xmlPartContent.getBytes()); Assert.assertEquals(xmlPart.getId(), xmlPartId); // XML parts can be referenced by collection index or GUID Assert.assertEquals(doc.getCustomXmlParts().get(0), xmlPart); Assert.assertEquals(doc.getCustomXmlParts().getById(xmlPartId), xmlPart); // Once the part is created, we can add XML schema associations like this xmlPart.getSchemas().add("http://www.w3.org/2001/XMLSchema"); // We can also clone parts and insert them into the collection directly CustomXmlPart xmlPartClone = xmlPart.deepClone(); xmlPartClone.setId(UUID.randomUUID().toString()); doc.getCustomXmlParts().add(xmlPartClone); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 2); // Iterate through collection with an enumerator and print the contents of each part Iterator<CustomXmlPart> enumerator = doc.getCustomXmlParts().iterator(); int index = 0; while (enumerator.hasNext()) { CustomXmlPart customXmlPart = enumerator.next(); System.out.println(MessageFormat.format("XML part index {0}, ID: {1}", index, customXmlPart.getId())); System.out.println(MessageFormat.format("\tContent: {0}", customXmlPart.getData())); index++; } // XML parts can be removed by index doc.getCustomXmlParts().removeAt(1); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 1); // The XML part collection itself can be cloned also CustomXmlPartCollection customXmlParts = doc.getCustomXmlParts().deepClone(); // And all elements can be cleared like this customXmlParts.clear(); // Create a StructuredDocumentTag that will display the contents of our part, // insert it into the document and save the document StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.PLAIN_TEXT, MarkupLevel.BLOCK); sdt.getXmlMapping().setMapping(xmlPart, "/root[1]/text[1]", ""); doc.getFirstSection().getBody().appendChild(sdt); doc.save(getArtifactsDir() + "StructuredDocumentTag.CustomXml.docx");
public void clear()
Example:
Shows how to create structured document tag with a custom XML data.Document doc = new Document(); // Construct an XML part that contains data and add it to the document's collection // Once the "Developer" tab in Mircosoft Word is enabled, // we can find elements from this collection as well as a couple defaults in the "XML Mapping Pane" String xmlPartId = UUID.randomUUID().toString(); String xmlPartContent = "<root><text>Hello, World!</text></root>"; CustomXmlPart xmlPart = doc.getCustomXmlParts().add(xmlPartId, xmlPartContent); // The data we entered resides in these variables Assert.assertEquals(xmlPart.getData(), xmlPartContent.getBytes()); Assert.assertEquals(xmlPart.getId(), xmlPartId); // XML parts can be referenced by collection index or GUID Assert.assertEquals(doc.getCustomXmlParts().get(0), xmlPart); Assert.assertEquals(doc.getCustomXmlParts().getById(xmlPartId), xmlPart); // Once the part is created, we can add XML schema associations like this xmlPart.getSchemas().add("http://www.w3.org/2001/XMLSchema"); // We can also clone parts and insert them into the collection directly CustomXmlPart xmlPartClone = xmlPart.deepClone(); xmlPartClone.setId(UUID.randomUUID().toString()); doc.getCustomXmlParts().add(xmlPartClone); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 2); // Iterate through collection with an enumerator and print the contents of each part Iterator<CustomXmlPart> enumerator = doc.getCustomXmlParts().iterator(); int index = 0; while (enumerator.hasNext()) { CustomXmlPart customXmlPart = enumerator.next(); System.out.println(MessageFormat.format("XML part index {0}, ID: {1}", index, customXmlPart.getId())); System.out.println(MessageFormat.format("\tContent: {0}", customXmlPart.getData())); index++; } // XML parts can be removed by index doc.getCustomXmlParts().removeAt(1); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 1); // The XML part collection itself can be cloned also CustomXmlPartCollection customXmlParts = doc.getCustomXmlParts().deepClone(); // And all elements can be cleared like this customXmlParts.clear(); // Create a StructuredDocumentTag that will display the contents of our part, // insert it into the document and save the document StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.PLAIN_TEXT, MarkupLevel.BLOCK); sdt.getXmlMapping().setMapping(xmlPart, "/root[1]/text[1]", ""); doc.getFirstSection().getBody().appendChild(sdt); doc.save(getArtifactsDir() + "StructuredDocumentTag.CustomXml.docx");
public CustomXmlPartCollection deepClone()
Example:
Shows how to create structured document tag with a custom XML data.Document doc = new Document(); // Construct an XML part that contains data and add it to the document's collection // Once the "Developer" tab in Mircosoft Word is enabled, // we can find elements from this collection as well as a couple defaults in the "XML Mapping Pane" String xmlPartId = UUID.randomUUID().toString(); String xmlPartContent = "<root><text>Hello, World!</text></root>"; CustomXmlPart xmlPart = doc.getCustomXmlParts().add(xmlPartId, xmlPartContent); // The data we entered resides in these variables Assert.assertEquals(xmlPart.getData(), xmlPartContent.getBytes()); Assert.assertEquals(xmlPart.getId(), xmlPartId); // XML parts can be referenced by collection index or GUID Assert.assertEquals(doc.getCustomXmlParts().get(0), xmlPart); Assert.assertEquals(doc.getCustomXmlParts().getById(xmlPartId), xmlPart); // Once the part is created, we can add XML schema associations like this xmlPart.getSchemas().add("http://www.w3.org/2001/XMLSchema"); // We can also clone parts and insert them into the collection directly CustomXmlPart xmlPartClone = xmlPart.deepClone(); xmlPartClone.setId(UUID.randomUUID().toString()); doc.getCustomXmlParts().add(xmlPartClone); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 2); // Iterate through collection with an enumerator and print the contents of each part Iterator<CustomXmlPart> enumerator = doc.getCustomXmlParts().iterator(); int index = 0; while (enumerator.hasNext()) { CustomXmlPart customXmlPart = enumerator.next(); System.out.println(MessageFormat.format("XML part index {0}, ID: {1}", index, customXmlPart.getId())); System.out.println(MessageFormat.format("\tContent: {0}", customXmlPart.getData())); index++; } // XML parts can be removed by index doc.getCustomXmlParts().removeAt(1); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 1); // The XML part collection itself can be cloned also CustomXmlPartCollection customXmlParts = doc.getCustomXmlParts().deepClone(); // And all elements can be cleared like this customXmlParts.clear(); // Create a StructuredDocumentTag that will display the contents of our part, // insert it into the document and save the document StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.PLAIN_TEXT, MarkupLevel.BLOCK); sdt.getXmlMapping().setMapping(xmlPart, "/root[1]/text[1]", ""); doc.getFirstSection().getBody().appendChild(sdt); doc.save(getArtifactsDir() + "StructuredDocumentTag.CustomXml.docx");
public CustomXmlPart getById(java.lang.String id)
id
- Case-sensitive string that identifies the custom XML part.null
if a custom XML part with the specified identifier is not found.Example:
Shows how to create structured document tag with a custom XML data.Document doc = new Document(); // Construct an XML part that contains data and add it to the document's collection // Once the "Developer" tab in Mircosoft Word is enabled, // we can find elements from this collection as well as a couple defaults in the "XML Mapping Pane" String xmlPartId = UUID.randomUUID().toString(); String xmlPartContent = "<root><text>Hello, World!</text></root>"; CustomXmlPart xmlPart = doc.getCustomXmlParts().add(xmlPartId, xmlPartContent); // The data we entered resides in these variables Assert.assertEquals(xmlPart.getData(), xmlPartContent.getBytes()); Assert.assertEquals(xmlPart.getId(), xmlPartId); // XML parts can be referenced by collection index or GUID Assert.assertEquals(doc.getCustomXmlParts().get(0), xmlPart); Assert.assertEquals(doc.getCustomXmlParts().getById(xmlPartId), xmlPart); // Once the part is created, we can add XML schema associations like this xmlPart.getSchemas().add("http://www.w3.org/2001/XMLSchema"); // We can also clone parts and insert them into the collection directly CustomXmlPart xmlPartClone = xmlPart.deepClone(); xmlPartClone.setId(UUID.randomUUID().toString()); doc.getCustomXmlParts().add(xmlPartClone); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 2); // Iterate through collection with an enumerator and print the contents of each part Iterator<CustomXmlPart> enumerator = doc.getCustomXmlParts().iterator(); int index = 0; while (enumerator.hasNext()) { CustomXmlPart customXmlPart = enumerator.next(); System.out.println(MessageFormat.format("XML part index {0}, ID: {1}", index, customXmlPart.getId())); System.out.println(MessageFormat.format("\tContent: {0}", customXmlPart.getData())); index++; } // XML parts can be removed by index doc.getCustomXmlParts().removeAt(1); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 1); // The XML part collection itself can be cloned also CustomXmlPartCollection customXmlParts = doc.getCustomXmlParts().deepClone(); // And all elements can be cleared like this customXmlParts.clear(); // Create a StructuredDocumentTag that will display the contents of our part, // insert it into the document and save the document StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.PLAIN_TEXT, MarkupLevel.BLOCK); sdt.getXmlMapping().setMapping(xmlPart, "/root[1]/text[1]", ""); doc.getFirstSection().getBody().appendChild(sdt); doc.save(getArtifactsDir() + "StructuredDocumentTag.CustomXml.docx");
public java.util.Iterator<CustomXmlPart> iterator()
Example:
Shows how to create structured document tag with a custom XML data.Document doc = new Document(); // Construct an XML part that contains data and add it to the document's collection // Once the "Developer" tab in Mircosoft Word is enabled, // we can find elements from this collection as well as a couple defaults in the "XML Mapping Pane" String xmlPartId = UUID.randomUUID().toString(); String xmlPartContent = "<root><text>Hello, World!</text></root>"; CustomXmlPart xmlPart = doc.getCustomXmlParts().add(xmlPartId, xmlPartContent); // The data we entered resides in these variables Assert.assertEquals(xmlPart.getData(), xmlPartContent.getBytes()); Assert.assertEquals(xmlPart.getId(), xmlPartId); // XML parts can be referenced by collection index or GUID Assert.assertEquals(doc.getCustomXmlParts().get(0), xmlPart); Assert.assertEquals(doc.getCustomXmlParts().getById(xmlPartId), xmlPart); // Once the part is created, we can add XML schema associations like this xmlPart.getSchemas().add("http://www.w3.org/2001/XMLSchema"); // We can also clone parts and insert them into the collection directly CustomXmlPart xmlPartClone = xmlPart.deepClone(); xmlPartClone.setId(UUID.randomUUID().toString()); doc.getCustomXmlParts().add(xmlPartClone); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 2); // Iterate through collection with an enumerator and print the contents of each part Iterator<CustomXmlPart> enumerator = doc.getCustomXmlParts().iterator(); int index = 0; while (enumerator.hasNext()) { CustomXmlPart customXmlPart = enumerator.next(); System.out.println(MessageFormat.format("XML part index {0}, ID: {1}", index, customXmlPart.getId())); System.out.println(MessageFormat.format("\tContent: {0}", customXmlPart.getData())); index++; } // XML parts can be removed by index doc.getCustomXmlParts().removeAt(1); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 1); // The XML part collection itself can be cloned also CustomXmlPartCollection customXmlParts = doc.getCustomXmlParts().deepClone(); // And all elements can be cleared like this customXmlParts.clear(); // Create a StructuredDocumentTag that will display the contents of our part, // insert it into the document and save the document StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.PLAIN_TEXT, MarkupLevel.BLOCK); sdt.getXmlMapping().setMapping(xmlPart, "/root[1]/text[1]", ""); doc.getFirstSection().getBody().appendChild(sdt); doc.save(getArtifactsDir() + "StructuredDocumentTag.CustomXml.docx");
public void removeAt(int index)
index
- The zero based index.Example:
Shows how to create structured document tag with a custom XML data.Document doc = new Document(); // Construct an XML part that contains data and add it to the document's collection // Once the "Developer" tab in Mircosoft Word is enabled, // we can find elements from this collection as well as a couple defaults in the "XML Mapping Pane" String xmlPartId = UUID.randomUUID().toString(); String xmlPartContent = "<root><text>Hello, World!</text></root>"; CustomXmlPart xmlPart = doc.getCustomXmlParts().add(xmlPartId, xmlPartContent); // The data we entered resides in these variables Assert.assertEquals(xmlPart.getData(), xmlPartContent.getBytes()); Assert.assertEquals(xmlPart.getId(), xmlPartId); // XML parts can be referenced by collection index or GUID Assert.assertEquals(doc.getCustomXmlParts().get(0), xmlPart); Assert.assertEquals(doc.getCustomXmlParts().getById(xmlPartId), xmlPart); // Once the part is created, we can add XML schema associations like this xmlPart.getSchemas().add("http://www.w3.org/2001/XMLSchema"); // We can also clone parts and insert them into the collection directly CustomXmlPart xmlPartClone = xmlPart.deepClone(); xmlPartClone.setId(UUID.randomUUID().toString()); doc.getCustomXmlParts().add(xmlPartClone); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 2); // Iterate through collection with an enumerator and print the contents of each part Iterator<CustomXmlPart> enumerator = doc.getCustomXmlParts().iterator(); int index = 0; while (enumerator.hasNext()) { CustomXmlPart customXmlPart = enumerator.next(); System.out.println(MessageFormat.format("XML part index {0}, ID: {1}", index, customXmlPart.getId())); System.out.println(MessageFormat.format("\tContent: {0}", customXmlPart.getData())); index++; } // XML parts can be removed by index doc.getCustomXmlParts().removeAt(1); Assert.assertEquals(doc.getCustomXmlParts().getCount(), 1); // The XML part collection itself can be cloned also CustomXmlPartCollection customXmlParts = doc.getCustomXmlParts().deepClone(); // And all elements can be cleared like this customXmlParts.clear(); // Create a StructuredDocumentTag that will display the contents of our part, // insert it into the document and save the document StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.PLAIN_TEXT, MarkupLevel.BLOCK); sdt.getXmlMapping().setMapping(xmlPart, "/root[1]/text[1]", ""); doc.getFirstSection().getBody().appendChild(sdt); doc.save(getArtifactsDir() + "StructuredDocumentTag.CustomXml.docx");