You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by jadiyo <ni...@lgim.co.uk> on 2006/05/04 11:28:39 UTC

removeChild from parent problem

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-from-parent-problem-t1555677.html#a4225767
Sent from the Xml Beans - User forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: removeChild from parent problem

Posted by Ben Jelloul Marouane <m....@nki.nl>.
Yes 2 #text because this is a xml format.

<Doc:AcctId>HERE THERE IS A #text
    <Doc:Id>HERE THERE IS A #text</Doc:Id>
</Doc:AcctId>

marouane
ps:keep all the previous messages inside next time it is easyer to reply
then.

On Thu, 2006-05-04 at 11:47, jadiyo wrote:
> Thanks Ben,
> 
> Firstly, I actually get two child nodes which is why I get #text appearing
> twice.  Why I get 2, I don;t know.
> 
> Secondly, is it safe to assume that a node name with #text can be removed?
> 
> Thank for the very quick response.
> 
> Jadiyo.
> 
> --
> View this message in context: http://www.nabble.com/removeChild-from-parent-problem-t1555677.html#a4225994
> Sent from the Xml Beans - User forum at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: removeChild from parent problem

Posted by jadiyo <ni...@lgim.co.uk>.
Thanks Ben,

Firstly, I actually get two child nodes which is why I get #text appearing
twice.  Why I get 2, I don;t know.

Secondly, is it safe to assume that a node name with #text can be removed?

Thank for the very quick response.

Jadiyo.

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


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: removeChild from parent problem

Posted by Ben Jelloul Marouane <m....@nki.nl>.
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-from-parent-problem-t1555677.html#a4225767
> Sent from the Xml Beans - User forum at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org