Page 1 of 1
How in element get inner XML
Posted: Tue Jul 17, 2012 6:33 pm
by Ship
Hi,
How I can get Inner XML from the 'p' element:
Code: Select all
<p class="- topic/p ">Concept <xref class="- topic/xref " href="../../Maps/concept.dita">definition</xref>. 123<b class="+ topic/ph hi-d/b "><i class="+ topic/ph hi-d/i "/></b>
</p>
Need some like this example result:
Code: Select all
Concept <xref class="- topic/xref " href="../../Maps/concept.dita">definition</xref>. 123<b class="+ topic/ph hi-d/b "><i class="+ topic/ph hi-d/i "/></b>
Do you have any idea for that problem?
Regards,
Ivan
Re: How in element get inner XML
Posted: Wed Jul 18, 2012 9:07 am
by Radu
Hi Ivan,
Please give us more details about what you want, do you want to obtain the content using the Author API or by applying an XSLT stylesheet over the original content?
From your previous posts I will assume you want to do this using Oxygen's API.
Here is a small code sample of copying the content of an AuthorElement to XML:
Code: Select all
AuthorNode nodeAtOffset = authorAccess.getDocumentController().getNodeAtOffset(authorAccess.getEditorAccess().getCaretOffset());
if(nodeAtOffset.getType() == AuthorNode.NODE_TYPE_ELEMENT) {
AuthorElement elementAtOffset = (AuthorElement) nodeAtOffset;
if("p".equals(elementAtOffset.getName())) {
//Paragraph.
if(elementAtOffset.getStartOffset() + 1 < elementAtOffset.getEndOffset()) {
//The content of "p" as a document fragment
AuthorDocumentFragment content = authorAccess.getDocumentController().createDocumentFragment(elementAtOffset.getStartOffset() + 1, elementAtOffset.getEndOffset() - 1);
//We can also serialize it to XML like:
String contentAsXML = authorAccess.getDocumentController().serializeFragmentToXML(content);
//Then you can use that content and insert it in another context like:
//authorAccess.getDocumentController().insertXMLFragment(contentAsXML, offset);
//or
//authorAccess.getDocumentController().insertFragment(offset, content);
} else {
//Empty element
}
} else {
//We could go up to find the paragraph using
// elementAtOffset.getParent();
}
}
Regards,
Radu
Re: How in element get inner XML
Posted: Wed Jul 18, 2012 12:05 pm
by Ship
Hi Radu,
Yes, I want to obtain the content using the Author API.
Your code sample fully resolved my problem.
Thanks for your help.
Regards,
Ivan