From: Loren C. <lor...@gm...> - 2011-05-02 20:31:09
|
I am in the process of building a document in memory that I am not in control of the order that the nodes to be added are coming, but want to create the document as simply as possible. The following is an example of the steps that would be received: Create document with root node 'item' Add node /item/one Add node /item/two/alpha Add node /item/three Add node /item/two/beta Add complex node /item/four/a Add another complex node /item/four/a Below are the steps as they should be in the document: <?xml version="1.0" encoding="UTF-8"?> <item/> <?xml version="1.0" encoding="UTF-8"?> <item> <one>foo</one> </item> <?xml version="1.0" encoding="UTF-8"?> <item> <one>foo</one> <two> <alpha>bar</alpha> </two> </item> <?xml version="1.0" encoding="UTF-8"?> <item> <one>foo</one> <two> <alpha>bar</alpha> </two> <three>qwerty</three> </item> <?xml version="1.0" encoding="UTF-8"?> <item> <one>foo</one> <two> <alpha>bar</alpha> <beta>1234</beta> </two> <three>qwerty</three> </item> <?xml version="1.0" encoding="UTF-8"?> <item> <one>foo</one> <two> <alpha>bar</alpha> <beta>1234</beta> </two> <three>qwerty</three> <four> <a> <p1>11</p1> <p2>12</p2> <p3>13</p3> <p4>14</p4> <p5>15</p5> <p6>16</p6> <p7>17</p7> <p8>18</p8> </a> <a> <p1>21</p1> <p2>22</p2> <p3>23</p3> <p4>24</p4> <p5>25</p5> <p6>26</p6> <p7>27</p7> <p8>28</p8> </a> </four> </item> I figure that I need to create a memtree document with the following: MemTreeBuilder builder = null; XQuery xquery = broker.getXQueryService(); if (xquery == null) { LOG.error("broker unable to retrieve XQueryService"); return null; } XQueryContext context = xquery.newContext(AccessContext.REST); builder = new MemTreeBuilder( context ); builder.startDocument(); builder.startElement( new QName( "item", null, null ), null ); builder.endElement(); builder.endDocument(); DocumentImpl document = builder.getDocument(); I would then use XUpdate to build the node structures in the steps as I showed above. How would I best implement the XUpdate? Thanks, Loren |