Plugin development - Accessing text nodes via AuthorElement
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 22
- Joined: Wed Jul 30, 2008 12:46 am
Plugin development - Accessing text nodes via AuthorElement
Hi there. I'm developing a plugin for use within the author perspective that will drop in a chunk of empty xml nodes that the user will then populate with data. What I'm trying to do is populate one of those empty xml nodes by determining the value of the previous sibling's text node where the node's names are equal, such that I can automatically populate one of the tags I'm inserting with an incremented value. -- I know that may not be very clear, so here's an example...
--existing xml--
<para>
<paraNum>1</paraNum>
<paraText>Some text</paraText>
</para>
<note>
<noteText>Some note text</note>
</note>
-- end existing xml--
--xml after plugin has run inserting a new "para" while the carrot focus is on the noteText--
<para>
<paraNum>1</paraNum>
<paraText>Some text</paraText>
</para>
<note>
<noteText>Some note text</note>
</note>
<para>
<paraNum>2</paraNum>
<paraText/>
</para>
----------------
The problem I'm having is determining the value of the previous <paraNum>'s value. I've written a serializer that takes the AuthorDocument from the AuthorNode.getOwnerDocument, and I'm attempting to create an in memory xmlDocument to xPath out the desired node. I'm thinking this is not the best way to go about it, but I'm at a loss as to how to proceed.
Any advice or direction would be greatly appreciated.
Thanks.
Cal.
--existing xml--
<para>
<paraNum>1</paraNum>
<paraText>Some text</paraText>
</para>
<note>
<noteText>Some note text</note>
</note>
-- end existing xml--
--xml after plugin has run inserting a new "para" while the carrot focus is on the noteText--
<para>
<paraNum>1</paraNum>
<paraText>Some text</paraText>
</para>
<note>
<noteText>Some note text</note>
</note>
<para>
<paraNum>2</paraNum>
<paraText/>
</para>
----------------
The problem I'm having is determining the value of the previous <paraNum>'s value. I've written a serializer that takes the AuthorDocument from the AuthorNode.getOwnerDocument, and I'm attempting to create an in memory xmlDocument to xPath out the desired node. I'm thinking this is not the best way to go about it, but I'm at a loss as to how to proceed.
Any advice or direction would be greatly appreciated.
Thanks.
Cal.
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: Plugin development - Accessing text nodes via AuthorElement
Post by sorin_ristache »
Hello,
You do not need to serialize the whole Author document and run an XPath expression on the serialized document. Just walk the DOM like tree of the Author document using the Author API available for custom Author actions.
If you want to find the paraNum that precedes the node where the cursor is located you can follow the parent link of the node received as parameter by your Author custom action using the method AuthorNode.getParent() until you find the AuthorElement for note. For example if the cursor is on the text contained in noteText the call getParent() returns an AuthorElement that is the noteText element and calling getParent() again returns the note element. After that call getParent() again to find the common parent of note and para. note can have more than one preceding para so you have to iterate through the child elements of the common parent (not displayed in your example XML fragment) until you find the para that precedes the note where the cursor is located. You iterate through the child elements by iterating through the list returned by calling getContentNodes() on the common parent element. You call the same method getContentNodes() on the para to get the paraNum with the number which you want to increment.
Regards,
Sorin
You do not need to serialize the whole Author document and run an XPath expression on the serialized document. Just walk the DOM like tree of the Author document using the Author API available for custom Author actions.
If you want to find the paraNum that precedes the node where the cursor is located you can follow the parent link of the node received as parameter by your Author custom action using the method AuthorNode.getParent() until you find the AuthorElement for note. For example if the cursor is on the text contained in noteText the call getParent() returns an AuthorElement that is the noteText element and calling getParent() again returns the note element. After that call getParent() again to find the common parent of note and para. note can have more than one preceding para so you have to iterate through the child elements of the common parent (not displayed in your example XML fragment) until you find the para that precedes the note where the cursor is located. You iterate through the child elements by iterating through the list returned by calling getContentNodes() on the common parent element. You call the same method getContentNodes() on the para to get the paraNum with the number which you want to increment.
Regards,
Sorin
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service