List Info

Thread: removeChild from parent problem




removeChild from parent problem
user name
2006-05-04 09:28:39
Hi,

I have the following xml fragment:

  <Doc:AcctId>
    <Doc:Id>
      <Doc:IBAN>SETTLEMENT SOURCE ACCOUNT
IBAN</Doc:IBAN>
    </Doc:Id>
  </Doc:AcctId>

I use the following code to remove the IBAN element from the
XML

Node ibanNode = <code to get theNode for the IBAN>
Node parentNode = ibanNode.getParentNode();
parentNode.removeChild(ibanNode);

This works fine, leaving just this :

  <Doc:AcctId>
    <Doc:Id></Doc:Id>
  </Doc:AcctId>

After we have removed the child, we want to check the
parentNode to see
whether it has more children.  In this case, the Id element
doesn't have
anymore children.
However, a call to parent.hasChildNodes() return true.
This is NOT what I expected.  So, I iterated over the child
nodes and output
the node name for each of the the nodes.  I got the
following result

nodeName = #text
nodeName = #text
 

Essentially, what I want to do is remove a child from its
parent and remove
the parent if it has no more children and so on and so
forth, but as
mentioned above, the parent node seems to have unexpected
children.


Thanks in advance for your help

Jadiyo


--
View this message in context: http://www.nabble.com/removeChild-fr
om-parent-problem-t1555677.html#a4225767
Sent from the Xml Beans - User forum at Nabble.com.


------------------------------------------------------------
---------
To unsubscribe, e-mail: user-unsubscribexmlbeans.apache.org
For additional commands, e-mail: user-helpxmlbeans.apache.org

removeChild from parent problem
user name
2006-05-04 09:32:54
the nodeName = #text
is the "empty" text between
<Doc:Id></Doc:Id>

I think if you play with nodes you could just check that if
it has 1
child and the nodeName = #text and theText == ""
just remove it.

Marouane

On Thu, 2006-05-04 at 11:28, jadiyo wrote:
> Hi,
> 
> I have the following xml fragment:
> 
>   <Doc:AcctId>
>     <Doc:Id>
>       <Doc:IBAN>SETTLEMENT SOURCE ACCOUNT
IBAN</Doc:IBAN>
>     </Doc:Id>
>   </Doc:AcctId>
> 
> I use the following code to remove the IBAN element
from the XML
> 
> Node ibanNode = <code to get theNode for the
IBAN>
> Node parentNode = ibanNode.getParentNode();
> parentNode.removeChild(ibanNode);
> 
> This works fine, leaving just this :
> 
>   <Doc:AcctId>
>     <Doc:Id></Doc:Id>
>   </Doc:AcctId>
> 
> After we have removed the child, we want to check the
parentNode to see
> whether it has more children.  In this case, the Id
element doesn't have
> anymore children.
> However, a call to parent.hasChildNodes() return true.
> This is NOT what I expected.  So, I iterated over the
child nodes and output
> the node name for each of the the nodes.  I got the
following result
> 
> nodeName = #text
> nodeName = #text
>  
> 
> Essentially, what I want to do is remove a child from
its parent and remove
> the parent if it has no more children and so on and so
forth, but as
> mentioned above, the parent node seems to have
unexpected children.
> 
> 
> Thanks in advance for your help
> 
> Jadiyo
> 
> 
> --
> View this message in context: http://www.nabble.com/removeChild-fr
om-parent-problem-t1555677.html#a4225767
> Sent from the Xml Beans - User forum at Nabble.com.
> 
> 
>
------------------------------------------------------------
---------
> To unsubscribe, e-mail: user-unsubscribexmlbeans.apache.org
> For additional commands, e-mail: user-helpxmlbeans.apache.org
> 


------------------------------------------------------------
---------
To unsubscribe, e-mail: user-unsubscribexmlbeans.apache.org
For additional commands, e-mail: user-helpxmlbeans.apache.org

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )