Aspose::Words::Markup::XmlMapping::get_PrefixMappings method
Contents
[
Hide
]XmlMapping::get_PrefixMappings method
Returns XML namespace prefix mappings to evaluate the XPath.
System::String Aspose::Words::Markup::XmlMapping::get_PrefixMappings() const
Remarks
Specifies the set of prefix mappings, which shall be used to interpret the XPath expression when the XPath expression is evaluated against the custom XML data parts in the document.
Examples
Shows how to set XML mappings for custom XML parts.
auto doc = System::MakeObject<Aspose::Words::Document>();
// Construct an XML part that contains text and add it to the document's CustomXmlPart collection.
System::String xmlPartId = System::Guid::NewGuid().ToString(u"B");
System::String xmlPartContent = u"<root><text>Text element #1</text><text>Text element #2</text></root>";
System::SharedPtr<Aspose::Words::Markup::CustomXmlPart> xmlPart = doc->get_CustomXmlParts()->Add(xmlPartId, xmlPartContent);
ASSERT_EQ(System::Text::Encoding::get_UTF8()->GetString(xmlPart->get_Data()), u"<root><text>Text element #1</text><text>Text element #2</text></root>");
// Create a structured document tag that will display the contents of our CustomXmlPart.
auto tag = System::MakeObject<Aspose::Words::Markup::StructuredDocumentTag>(doc, SdtType::PlainText, MarkupLevel::Block);
// Set a mapping for our structured document tag. This mapping will instruct
// our structured document tag to display a portion of the XML part's text contents that the XPath points to.
// In this case, it will be contents of the the second "<text>" element of the first "<root>" element: "Text element #2".
tag->get_XmlMapping()->SetMapping(xmlPart, u"/root[1]/text[2]", u"xmlns:ns='http://www.w3.org/2001/XMLSchema'");
ASSERT_TRUE(tag->get_XmlMapping()->get_IsMapped());
ASPOSE_ASSERT_EQ(tag->get_XmlMapping()->get_CustomXmlPart(), xmlPart);
ASSERT_EQ(tag->get_XmlMapping()->get_XPath(), u"/root[1]/text[2]");
ASSERT_EQ(tag->get_XmlMapping()->get_PrefixMappings(), u"xmlns:ns='http://www.w3.org/2001/XMLSchema'");
// Add the structured document tag to the document to display the content from our custom part.
doc->get_FirstSection()->get_Body()->AppendChild<System::SharedPtr<Aspose::Words::Markup::StructuredDocumentTag>>(tag);
doc->Save(get_ArtifactsDir() + u"StructuredDocumentTag.XmlMapping.docx");
See Also
- Class XmlMapping
- Namespace Aspose::Words::Markup
- Library Aspose.Words for C++