"Inserting" a sibling node into XML chunk returns an unexpected number of nodes: 4 instead of 2.

j13elliott
j13elliott's picture
User offline. Last seen 1 year 11 weeks ago. Offline
Joined: 03/13/2009
Points: 80

I've attached a kludgy attempt I made in emml to 'force' Presto to create a JSON array, not a JSON object, of savedQueries by 'adding' a sibling savedQuery node to the original single one, when only one exists:

    <constructor outputvariable="result">
      <SavedQueriesResponse>
        <SavedQueries>
          <SavedQuery>
            <queryid>435</queryid>
            <title>Query # 1 </title>
            <creationdate>1254027600000</creationdate>
            <modificationdate>1254027600000</modificationdate>
            <shared>1</shared>
          </SavedQuery>
        </SavedQueries>
      </SavedQueriesResponse>
    </constructor>

Running the standalone emml attachment does almost what I want.

The problem is that the assignment operation (below) doesn't replace the existing SavedQueries parent node's content with the 2 savedQuery nodes from result2. 

Somehow, 4 savedquery children are placed under the parent instead of 2.

<assign fromexpr="$result2//result/*" toexpr="$result//SavedQueriesResponse/SavedQueries" />

I'm hoping that there's something obvious that I've overlooked.

Thanks,

-John

0
Your rating: None
raj
raj's picture
User offline. Last seen 1 week 5 days ago. Offline
Joined: 09/22/2008
Points: 4

 Hi John,

This could be a bug in toexpr - we will investigate it further.

Meanwhile, can you use this 'annotate' based approach :

 

<constructor outputvariable="result">

     <SavedQueriesResponse>

       <SavedQueries>

         <SavedQuery>

           <queryid>435</queryid>

           <title>Query # 1 </title>

           <creationdate>1254027600000</creationdate>

           <modificationdate>1254027600000</modificationdate>

           <shared>1</shared>

         </SavedQuery>

       </SavedQueries>

     </SavedQueriesResponse>

   </constructor>

    <annotate variable="result" expr="/SavedQueriesResponse/SavedQueries" >

           element SavedQuery { $result//SavedQuery/* }

    </annotate>

 
 
Output :
 
<SavedQueriesResponse>
   <SavedQueries>
      <SavedQuery>
         <queryid>435</queryid>
         <title>Query # 1 </title>
         <creationdate>1254027600000</creationdate>
         <modificationdate>1254027600000</modificationdate>
         <shared>1</shared>
      </SavedQuery>
      <SavedQuery>
         <queryid>435</queryid>
         <title>Query # 1 </title>
         <creationdate>1254027600000</creationdate>
         <modificationdate>1254027600000</modificationdate>
         <shared>1</shared>
      </SavedQuery>
   </SavedQueries>
</SavedQueriesResponse>
 

 

raj.  chief masher @ jackbe