You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@axis.apache.org by Kasun Indrasiri <ka...@gmail.com> on 2008/02/05 05:09:04 UTC

Cloning a portion of a XML tree using axiom

Hi,
I want to get a copy of a portion of a XML tree using Axiom. Actually what I
have is an axiom node which contains:

<sp:IssuedToken sp:IncludeToken="xs:anyURI" ... >
   <sp:Issuer>wsa:EndpointReferenceType</sp:Issuer>
   <sp:RequestSecurityTokenTemplate TrustVersion="xs:anyURI" >
   …………..
   </sp:RequestSecurityTokenTemplate>
   <wsp:Policy>
    <sp:RequireDerivedKeys ... />
    <sp:RequireExternalReference ... />
    <sp:RequireInternalReference ... />
   </wsp:Policy>
</sp:IssuedToken>

Simply, I want to extract a copy of the content of
'RequestSecurityTokenTemplate'. Can we do this by using axiom.

Thanks.

Kasun.

Re: Cloning a portion of a XML tree using axiom

Posted by Dinesh Premalal <xy...@gmail.com>.
Hi Kausn,

I think, axis-c-user list is more appropriate for this kind of a question.
However it is not a hard and fast rule. Just my 2c

thanks,
Dinesh

-- 
http://nethu.org/

Re: Cloning a portion of a XML tree using axiom

Posted by Kasun Indrasiri <ka...@gmail.com>.
Hi Dinesh,

This would solve the problem.
Thanks.

Kasun

Re: Cloning a portion of a XML tree using axiom

Posted by Dinesh Premalal <xy...@gmail.com>.
Kasun,

"Kasun Indrasiri" <ka...@gmail.com> writes:
>  
> What I really want to acheive is this.
> - Initially I got an axiom_node which contains <sp:IssuedToken> ......
>  and I want to get a new copy (separate memory allocation) of
> a content of that node (say things with the <RequestSecurityTokenTemplate>
>  qname ).
> - And also once the main node is freed, the extracted part should
> not be freed.

Try to detach your child node from parent

    AXIS2_EXTERN axiom_node_t *AXIS2_CALL
    axiom_node_detach(
        axiom_node_t * om_node,
        const axutil_env_t * env);


> - I wonder whether Jimmy's solution would work with axiom.

It is not working with axiom, however you could use it as alternate
method.

thanks,
Dinesh
-- 
http://nethu.org

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


RE: Cloning a portion of a XML tree using axiom

Posted by Bill Mitchell <bm...@austin.rr.com>.
Hi Kasun,

 

In my application I found I had a similar need to clone all of an axiom
sub-tree.  Unlike the Xerces C++ package, the Axiom C package doesn't have a
built-in clone method.  Axiom does have all the underlying methods, though,
to traverse the tree and build new nodes that replicate the old nodes, so I
wrote my own clone.  Along the way I discovered that I needed something more
specialized than a general clone, to conditionally keep or discard
attributes and text associated with elements.  As well, I had to avoid some
of the Axiom methods, particularly the iterator methods, as I am sometimes
sharing the one source document across multiple threads.

 

As I was writing in C++, the end result isn't suitable to be a contribution
to Axiom.  The code throws exceptions to handle errors, instead of the
Axis/Axiom C technique of returning status codes.  Recursively traversing
the tree to clone each subtree is pretty straightforward, but looking at my
code could give you a jump start on handling namespaces and attributes as
the nodes and elements are reached along the way.  If you want a copy of the
routines I wrote, I can send them to you as an attachment off-list.  If you
are going to a C environment, you will need to replace all the error
handling and the C++ style comments; if you are in a C++ environment,
replacing the exceptions with something from your environment will be
straightforward.  

 

Bill Mitchell

wtmitchell3@acm.org

 

From: Kasun Indrasiri [mailto:kasun147@gmail.com] 
Sent: Tuesday, February 05, 2008 5:32 AM
To: Apache AXIS C Developers List
Subject: Re: Cloning a portion of a XML tree using axiom

 


Hi,

In the case of using  axiom_element_get_children_with_qname(...) method,
once the initial axiom_node is freed (say sec-policy is freed in above
example) then the node that we extracted through the iterator (which is to
be used for WS-Trust ) will be also freed.
 
What I really want to acheive is this.
- Initially I got an axiom_node which contains <sp:IssuedToken> ......  and
I want to get a new copy (separate memory allocation) of a content of that
node (say things with the <RequestSecurityTokenTemplate>  qname ).
- And also once the main node is freed, the extracted part should not be
freed. 
- I wonder whether Jimmy's solution would work with axiom. 

Thanks,
Kasun.




Re: Cloning a portion of a XML tree using axiom

Posted by Kasun Indrasiri <ka...@gmail.com>.
Hi,

In the case of using
axiom_element_get_children_with_qname(...) method,  once the initial
axiom_node is freed (say
sec-policy is freed in above
example) then the node that we extracted through the iterator (which is to
be used for WS-Trust ) will be also freed.

What I really want to acheive is this.
- Initially I got an axiom_node which contains <sp:IssuedToken> ......
 and I want to get a new copy (separate memory allocation) of
a content of that node (say things with the <RequestSecurityTokenTemplate>
 qname ).
- And also once the main node is freed, the extracted part should not be
freed.
- I wonder whether Jimmy's solution would work with axiom.

Thanks,
Kasun.

Re: Cloning a portion of a XML tree using axiom

Posted by jimmy Zhang <jz...@ximpleware.com>.
I think in VTD-XML you can use getElementFragment() or getElementFragmentNS() to directly extract
the byte arrays corresponding to the XML tree...
which is a lot more efficient than tree parsing

Cheers,
Jimmy
  ----- Original Message ----- 
  From: Kasun Indrasiri 
  To: Apache AXIS C Developers List 
  Sent: Monday, February 04, 2008 8:09 PM
  Subject: Cloning a portion of a XML tree using axiom


  Hi,
  I want to get a copy of a portion of a XML tree using Axiom. Actually what I have is an axiom node which contains:

  <sp:IssuedToken sp:IncludeToken="xs:anyURI" ... >
     <sp:Issuer>wsa:EndpointReferenceType</sp:Issuer>
     <sp:RequestSecurityTokenTemplate TrustVersion="xs:anyURI" > 
     …………..
     </sp:RequestSecurityTokenTemplate>
     <wsp:Policy>
      <sp:RequireDerivedKeys ... />
      <sp:RequireExternalReference ... />
      <sp:RequireInternalReference ... />
     </wsp:Policy>
  </sp:IssuedToken>

  Simply, I want to extract a copy of the content of 'RequestSecurityTokenTemplate'. Can we do this by using axiom.

  Thanks.

  Kasun.



Re: Cloning a portion of a XML tree using axiom

Posted by Dinesh Premalal <xy...@gmail.com>.
Hi Kasun,


On Feb 5, 2008 9:39 AM, Kasun Indrasiri <ka...@gmail.com> wrote:

> <sp:IssuedToken sp:IncludeToken="xs:anyURI" ... >
>    <sp:Issuer>wsa:EndpointReferenceType</sp:Issuer>
>    <sp:RequestSecurityTokenTemplate TrustVersion="xs:anyURI" >
>    …………..
>    </sp:RequestSecurityTokenTemplate>
>    <wsp:Policy>
>     <sp:RequireDerivedKeys ... />
>     <sp:RequireExternalReference ... />
>     <sp:RequireInternalReference ... />
>    </wsp:Policy>
> </sp:IssuedToken>
>
> Simply, I want to extract a copy of the content of
> 'RequestSecurityTokenTemplate'. Can we do this by using axiom.


I think you can use

    AXIS2_EXTERN axiom_children_qname_iterator_t *AXIS2_CALL
    axiom_element_get_children_with_qname(
        axiom_element_t * om_element,
        const axutil_env_t * env,
        axutil_qname_t * element_qname,
        axiom_node_t * element_node);

function to get children from axiom tree.

thanks,
Dinesh
-- 
http://nethu.org/