InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SnpManipulateXMLElements Class Reference

Public Member Functions

 SnpManipulateXMLElements ()
 
virtual ~SnpManipulateXMLElements ()
 
XMLReference GetDocumentElementRef (const UIDRef &documentUIDRef)
 
void GetFlattenedElementList (const UIDRef &documentUIDRef, K2Vector< XMLReference > &outElems)
 
XMLReference GetRootElementRef (const UIDRef &documentUIDRef)
 
ErrorCode CreateElements (const XMLReference &parentXMLReference, const PMString &tagName, int32 numElements, K2Vector< XMLReference > &outElementsCreated)
 
ErrorCode CreateAttributes (const K2Vector< XMLReference > &elements, const PMString &attribName, const PMString &attribValue)
 
ErrorCode CreateComment (const XMLReference &parentXMLReference, const PMString &commentText, XMLReference &outXMLReferenceCreated)
 
ErrorCode CreateProcessingInstruction (const XMLReference &parentXMLReference, const PMString &piKey, const PMString &piValue, XMLReference &outXMLReferenceCreated)
 
ErrorCode ModifyComment (const XMLReference &commentXMLReference, const PMString &newCommentText)
 
ErrorCode ModifyProcessingInstruction (const XMLReference &piXMLReference, const PMString &newPiKey, const PMString &newPiValue)
 
ErrorCode TagGraphic (const PMString &tagName, const UIDRef &graphicFrameUIDRef)
 
ErrorCode TagStoryThroughFrame (const PMString &tagName, const UIDRef &textFrameContainerUIDRef)
 
ErrorCode TagStory (const PMString &tagName, const UIDRef &textModelUIDRef)
 
ErrorCode TagTable (const UIDRef &tableModelUIDRef, const PMString &tableTagName, const PMString &cellTagName, XMLReference &outCreatedXMLReference)
 
ErrorCode TagTextRange (const UIDRef &textModelUIDRef, const PMString &tagName, const TextIndex &startIndex, const TextIndex &endIndex)
 
void ValidateFromRoot (IActiveContext *context)
 
void ValidateFromElement (const XMLReference &xmlRef)
 

Detailed Description

  • How to obtain list of all elements
  • How to obtain reference to root or document element
  • How to associate a DTD with the logical structure
  • How to create elements in the logical structure
  • How to create XML comments and processing instructions
  • How to modify comments and processing instructions
  • How to tag a graphic frame (IGraphicFrameData) for instance as image placeholder
  • How to tag a story (kTextStoryBoss)
  • how to tag a table (kTableModelBoss)
  • How to tag a text range
  • How to validate logical structure against a DTD

Once you have run the snippet options, an interesting thing to do is try using SnpInspectSelectionXMLProperties to find out something about what has been created. For instance, if you run TagGraphic, select the frame in the layout view and run SnpInspectSelectionXMLProperties.

Exercising

AcquireElements

  1. Create a new document
  2. Run the snippet ManipulateXMLElements
  3. Choose the option AcquireElements.
  4. If all is well, there should be no asserts (if in debug build).

    AssociateDTD

  1. Create a new document
  2. Run the snippet ManipulateXMLElements
  3. Choose the option AssociateDTD.
  4. If all is well, there should be no asserts (if in debug build).

    CreateElementsAndAttributes

  1. Create a new document
  2. Run the snippet ManipulateXMLElements
  3. Choose the option CreateElementsAndAttributes.
  4. If all is well, there should be no asserts (if in debug build).
  5. You should see some elements with attributes in the logical structure

    CreateComment/PI

  1. Create a new document
  2. Run the snippet ManipulateXMLElements
  3. Choose the option CreateComment/PI.
  4. If all is well, there should be no asserts (if in debug build).
  5. You should see some new comment/PI in logical structure

    ModifyComment/PI

  1. Create a new document
  2. Run the snippet ManipulateXMLElements
  3. Choose the option ModifyComment/PI.
  4. If all is well, there should be no asserts (if in debug build).
  5. You should see comment/PI in logical structure created, which was the thing modified

    TagGraphic

  1. Create a new document
  2. Run the snippet ManipulateXMLElements
  3. Choose the option TagGraphic.
  4. If all is well, there should be no asserts (if in debug build).
  5. You should see a placeholder graphic created and tagged

    TagStory

  1. Create a new document
  2. Run the snippet ManipulateXMLElements
  3. Choose the option TagStory.
  4. If all is well, there should be no asserts (if in debug build).

    TagTable

  1. Create a new document
  2. Run the snippet ManipulateXMLElements
  3. Choose the option TagTable.
  4. If all is well, there should be no asserts (if in debug build).

    TagTextRange

  1. Create a new document
  2. Run the snippet ManipulateXMLElements
  3. Choose the option TagTextRange.
  4. If all is well, there should be no asserts (if in debug build).

    ValidateAgainstDTD

  1. Create a new document
  2. Run the snippet ManipulateXMLElements
  3. Choose the option ValidateAgainstDTD.
  4. If all is well, there should be no asserts (if in debug build).
See Also
_SnpRunnerManipulateXMLElements::Run for driver code

Constructor & Destructor Documentation

SnpManipulateXMLElements::SnpManipulateXMLElements ()
inline

Constructor

virtual SnpManipulateXMLElements::~SnpManipulateXMLElements ()
inlinevirtual

Destructor

Member Function Documentation

ErrorCode SnpManipulateXMLElements::CreateAttributes (const K2Vector< XMLReference > & elements,
const PMStringattribName,
const PMStringattribValue 
)

Create a new attribute for the elements supplied

Precondition
each element in elements should allow IIDXMLElement to be instantiated
attribName shouldn't already exist on the elements supplied
Parameters
elements
attribNamename of attribute
attribValuevalue for the attribute
Returns
ErrorCode kSuccess on success, other ErrorCode otherwise
ErrorCode SnpManipulateXMLElements::CreateComment (const XMLReferenceparentXMLReference,
const PMStringcommentText,
XMLReferenceoutXMLReferenceCreated 
)

Create a new XML comment (kXMLCommentBoss)

Precondition
parentXMLReference should allow IIDXMLElement to be instantiated
Parameters
parentXMLReferenceparent in logical structure for new element
commentTextwhat the comment should contain
outXMLReferenceCreatedallows IIDXMLElement to be instantiated for new element (kXMLCommentBoss)
Returns
ErrorCode kSuccess on success, other ErrorCode otherwise
ErrorCode SnpManipulateXMLElements::CreateElements (const XMLReferenceparentXMLReference,
const PMStringtagName,
int32 numElements,
K2Vector< XMLReference > & outElementsCreated 
)

Create element(s) in document with given parent

Precondition
parentXMLReference should allow IIDXMLElement to be instantiated
Parameters
parentXMLReferenceparent for newly created element(s)
tagNamespecifies tag to use for created element(s)
numElementshow many elements to create
outElementsCreatedstores the references to elements created
Returns
ErrorCode kSuccess on success, other ErrorCode otherwise
ErrorCode SnpManipulateXMLElements::CreateProcessingInstruction (const XMLReferenceparentXMLReference,
const PMStringpiKey,
const PMStringpiValue,
XMLReferenceoutXMLReferenceCreated 
)

Create a processing instruction (kXMLPIBoss)

Precondition
parentXMLReference should allow IIDXMLElement to be instantiated
Parameters
parentXMLReference
piKeykey for the PI to create
piValuevalue for the PI to create
outXMLReferenceCreatedallows IIDXMLElement to be instantiated for new element (kXMLPIBoss)
Returns
ErrorCode kSuccess on success, other ErrorCode otherwise
XMLReference SnpManipulateXMLElements::GetDocumentElementRef (const UIDRefdocumentUIDRef)

Obtain reference to document element (kXMLDocumentBoss)

Precondition
documentUIDRef should allow IDocument to be instantiated
Parameters
documentUIDRefspecifies document of interest
Returns
XMLReference to document element
See Also
IXMLUtils::QueryDocElement
void SnpManipulateXMLElements::GetFlattenedElementList (const UIDRefdocumentUIDRef,
K2Vector< XMLReference > & outElems 
)

Obtain list of all elements in document

Precondition
documentUIDRef should allow IDocument to be instantiated
Parameters
documentUIDRefspecifies document of interest
outElemsOUT stores list of elements in the document
XMLReference SnpManipulateXMLElements::GetRootElementRef (const UIDRefdocumentUIDRef)

Obtain reference to root element

Precondition
documentUIDRef should allow IDocument to be instantiated
Returns
XMLReference
See Also
IXMLUtils::QueryRootElement
ErrorCode SnpManipulateXMLElements::ModifyComment (const XMLReferencecommentXMLReference,
const PMStringnewCommentText 
)

Modify text of an existing comment

Precondition
commentXMLReference should allow IIDXMLElement to be instantiated
Parameters
commentXMLReference
newCommentText
Returns
ErrorCode kSuccess on success, other ErrorCode otherwise
ErrorCode SnpManipulateXMLElements::ModifyProcessingInstruction (const XMLReferencepiXMLReference,
const PMStringnewPiKey,
const PMStringnewPiValue 
)

Modify properties of an existing processing instruction

Precondition
piXMLReference should allow IIDXMLElement to be instantiated
Parameters
piXMLReference
newPiKey
newPiValue
Returns
ErrorCode kSuccess on success, other ErrorCode otherwise
ErrorCode SnpManipulateXMLElements::TagGraphic (const PMStringtagName,
const UIDRefgraphicFrameUIDRef 
)

Assign tag to a graphic frame

Precondition
graphicFrameUIDRef should allow IGraphicFrameData to be instantiated
Parameters
tagName
graphicFrameUIDRef
Returns
ErrorCode kSuccess on success, other ErrorCode otherwise
ErrorCode SnpManipulateXMLElements::TagStory (const PMStringtagName,
const UIDReftextModelUIDRef 
)

Assign tag to a story

Precondition
textModelUIDRef should allow ITextModel to be instantiated
Parameters
tagName
textModelUIDRef
Returns
ErrorCode kSuccess on success, other ErrorCode otherwise
ErrorCode SnpManipulateXMLElements::TagStoryThroughFrame (const PMStringtagName,
const UIDReftextFrameContainerUIDRef 
)

Assign a tag to a story through its associated text frame

Precondition
textFrameContainerUIDRef should allow IHierarchy to be instantiated
textFrameContainerUIDRef have zeroth child with IMultiColumnTextFrame
Parameters
tagNamespecifies name of tag to apply, is created if not existing
textFrameContainerUIDRefidentifies text frame
Returns
ErrorCode kSuccess on success, other ErrorCode otherwise
ErrorCode SnpManipulateXMLElements::TagTable (const UIDReftableModelUIDRef,
const PMStringtableTagName,
const PMStringcellTagName,
XMLReferenceoutCreatedXMLReference 
)

Assign tag to a table, and tag the cells too.

Precondition
story in which table is located should already be tagged
tableModelUIDRef should allow ITableModel to be instantiated
Parameters
tableModelUIDRefidentifies table
tableTagNametag to apply to table
cellTagNametag to apply to cells
outCreatedXMLReferencestores element created from which IIDXMLElement can be instantiated
Returns
ErrorCode kSuccess on success, other ErrorCode otherwise
ErrorCode SnpManipulateXMLElements::TagTextRange (const UIDReftextModelUIDRef,
const PMStringtagName,
const TextIndex & startIndex,
const TextIndex & endIndex 
)

Assign tag to a range of text in a story

Precondition
story should already be tagged
textModelUIDRef should allow ITextModel to be instantiated
Parameters
textModelUIDRefstory
tagNamename of tag to apply
startIndexbeginning of range to tag
endIndexend of range to tag
Returns
ErrorCode kSuccess on success, other ErrorCode otherwise
void SnpManipulateXMLElements::ValidateFromElement (const XMLReferencexmlRef)

Validate logical structure against associated DTD from specified element.

Precondition
xmlRef should allow IIDXMLElement to be instantiated
Parameters
xmlRefspecifies element (IIDXMLElement) from which to start validating
void SnpManipulateXMLElements::ValidateFromRoot (IActiveContextcontext)

Validates the logical structure of document against associated DTD using an action executed via the action manager (IActionManager). Needs active context (IActiveContext) to drive method on action manager (IActionManager)

Parameters
contextcurrent active context