How in element get inner XML

Having trouble installing Oxygen? Got a bug to report? Post it all here.
Ship
Posts: 5
Joined: Thu Jun 07, 2012 10:37 am

How in element get inner XML

Post 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
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: How in element get inner XML

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Ship
Posts: 5
Joined: Thu Jun 07, 2012 10:37 am

Re: How in element get inner XML

Post 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
Post Reply