You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by "Christian Baune (Jira)" <ji...@apache.org> on 2021/09/16 12:24:00 UTC

[jira] [Commented] (XMLBEANS-570) Bookmark are not copied when you copy cursors

    [ https://issues.apache.org/jira/browse/XMLBEANS-570?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17416077#comment-17416077 ] 

Christian Baune commented on XMLBEANS-570:
------------------------------------------

I don't think it did work. So the docs have to be amended.

Now, I am totally clueless on how to keep an hold on the cloned element as it seems there is a side channel communication: cursors move to copied element too. (bookmark get cleared from original element)

So the doc should read something like:

move bookmark to the newly added element (original bookmark is cleared).

Also, push and pop are moved too. So you cant "push", "copy" then "pop" and expect to find the original element. There is in fact no real way to reach original element besides "toPrevSibling".

> Bookmark are not copied when you copy cursors
> ---------------------------------------------
>
>                 Key: XMLBEANS-570
>                 URL: https://issues.apache.org/jira/browse/XMLBEANS-570
>             Project: XMLBeans
>          Issue Type: Bug
>          Components: Cursor, XmlObject
>    Affects Versions: Version 5.0.0
>         Environment: UbuntuLinux, XMLBean 5.0.0
>            Reporter: Christian Baune
>            Priority: Major
>
> Documentation state:
> {quote}The cursors and bookmarks located in the XML that was copied are also copied to the new location.
> {quote}
> It does not copy the bookmark, but moves it.
> It also move the original cursor.
> When running the code bellow, the expected output is:
> {noformat}
> <a>Test 1</a>
> <a>modified</a>{noformat}
> The current output is:
> {noformat}
> <a>Test 1</a>{noformat}
> Code (Kotlin) to reproduce the issue:
> {code:none}
> data class TestBookmark(val key:String): XmlCursor.XmlBookmark(){
>     override fun getKey():Any{
>         return key
>     }
> }
> fun main(){
>     @Language("XML") val xml="""<r>
>         |<a>Test 1</a>
>         |<a>Test 2</a>
>         |<a>Test 3</a>
>         |<a>Test 4</a>
>         |</r>""".trimMargin()
>     val xmlObj=XmlObject.Factory.parse(xml)
>     val bk=TestBookmark("test")
>     xmlObj.newCursor().use { cur->
>         cur.advanceTo(QName("a"))
>         cur.setBookmark(bk)
>         cur.newCursor().use { here ->
>             // Per doc: The cursors and bookmarks located in the XML that was copied are also copied to the new location.
>             cur.copyXml(here)
>             here.textValue="changed"
>         }
>     }
>     xmlObj.newCursor().use { cur->
>         while (cur.toNextBookmark("test")!=null){
>             // Expect to print <a>Test 1</a> and <a>changed</a>
>             println(cur.xmlText())
>         }
>     }
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org