Selected text from Author to xmlfragment
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 2
- Joined: Sun Oct 24, 2010 9:45 am
Selected text from Author to xmlfragment
Hello,
I have a problem with the selected text after the serialization.
I use for that:
I have the selection from the original xml like:
After the serializeFragmentToXML the text will be:
String selectionAsXML -> "<container>[space]<format>text</format>[space]</container>"
I have [space] in the text. That isn't correct for me because I want make some changes on text.
How can I get the serialized text like the original text selected without spaces, like ?
String selectionAsXML -> "<container><format>text</format></container>"
Thanks!
Calin
I have a problem with the selected text after the serialization.
I use for that:
Code: Select all
if(authorAccess.getEditorAccess().hasSelection()) {
AuthorDocumentController documentController = authorAccess.getDocumentController();
AuthorDocumentFragment selectionAsAFragment = documentController.createDocumentFragment(
authorAccess.getEditorAccess().getSelectionStart(), authorAccess.getEditorAccess().getSelectionEnd());
String selectionAsXML = documentController.serializeFragmentToXML(selectionAsAFragment);
//Deletes the selection
authorAccess.getEditorAccess().deleteSelection();
//Process the selectionAsXML fragment, modify it.
//................
//Insert the XML fragment back at caret position.
documentController.insertXMLFragment(selectionAsXML, authorAccess.getEditorAccess().getCaretOffset());
}
Code: Select all
<container>
<format>text</format>
</container>
String selectionAsXML -> "<container>[space]<format>text</format>[space]</container>"
I have [space] in the text. That isn't correct for me because I want make some changes on text.
How can I get the serialized text like the original text selected without spaces, like ?
String selectionAsXML -> "<container><format>text</format></container>"
Thanks!
Calin
-
- Posts: 9450
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Selected text from Author to xmlfragment
Dear Calin,
So the original XML content looks like this, right?
That line break that you have before the <format> element is still considered to be a whitespace and when the XML is loaded in the Author editing mode it gets converted to a single space.
Does the DTD/XML Schema associated to the XML specify that the <container> element has element-only content (without the possibility to have text between the <format> elements for example)? If it would, then Oxygen would remove that extra space when presenting the document in the Author editing mode.
Regards,
Radu
So the original XML content looks like this, right?
Code: Select all
<container>
<format>text</format>
</container>
Does the DTD/XML Schema associated to the XML specify that the <container> element has element-only content (without the possibility to have text between the <format> elements for example)? If it would, then Oxygen would remove that extra space when presenting the document in the Author editing mode.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 2
- Joined: Sun Oct 24, 2010 9:45 am
Re: Selected text from Author to xmlfragment
Thank you Radu for very rapid answer.
I knew your solution.
Unfortunately <container> may contain PCDATA. That xml fragment is like:
1.
2.
So, after documentController.serializeFragmentToXML the text will be:
1. -> <div>text1 <b>text2 text3</b> text4</div>
2. -> <div>[space]text1 <b>text2 text3</b> text4[space]</div>
The resulted texts are different from the same original selection.
A workaround can be to get the fragment from original xml but I can't get the selected nodes into original xml.
Maybe with: java.lang.String getXPathExpression(int offset) get the xpath from author mode and will apply that to the original xml. I don't know.
What do you think is possible a workaround for that ?
Thanks!
Calin
I knew your solution.
Unfortunately <container> may contain PCDATA. That xml fragment is like:
1.
Code: Select all
<div>text1 <b>text2 text3</b> text4</div>
Code: Select all
<div>
text1 <b>text2 text3</b> text4
</div>
1. -> <div>text1 <b>text2 text3</b> text4</div>
2. -> <div>[space]text1 <b>text2 text3</b> text4[space]</div>
The resulted texts are different from the same original selection.
A workaround can be to get the fragment from original xml but I can't get the selected nodes into original xml.
Maybe with: java.lang.String getXPathExpression(int offset) get the xpath from author mode and will apply that to the original xml. I don't know.
What do you think is possible a workaround for that ?
Thanks!
Calin
-
- Posts: 9450
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Selected text from Author to xmlfragment
Hi Calin,
Just to see that I understand your example:
So in the first case there is no space or line break between the <div> and the text1. And in the second case you have a line break between them.
When the edited content the Author mode is obtained by normalizing all spaces so that line break will be converted to a space.
There is no possibility for you to obtain the XML content exactly as it was from the Author API other than setting the <div> element as space preserve in the CSS, something like:
I'm afraid I still do not understand your original use case, why you need the serialization of the AuthorDocumentFragment to be precisely what the XML contained and not an equivalent of that.
Regards,
Radu
Just to see that I understand your example:
So in the first case there is no space or line break between the <div> and the text1. And in the second case you have a line break between them.
When the edited content the Author mode is obtained by normalizing all spaces so that line break will be converted to a space.
There is no possibility for you to obtain the XML content exactly as it was from the Author API other than setting the <div> element as space preserve in the CSS, something like:
Code: Select all
div {
white-space:pre;
}
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ 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