Hi Enda,

At 11:38 AM 6/8/2006 +0100, Mannion, Enda wrote:
Hi,

I would like to remove all of person1 and its child tags below.

- <<Contacts>
- <  <Person1>
  <           <ContactType>Partner</ContactType>
 <FirstName>y</FirstName>
         <LastName>y</LastName>
      <Salutation>y</Salutation>
         <Title>y</Title>
      <EmailAddress>y</EmailAddress>
      <TelephoneNumber>y</TelephoneNumber>
      <PreferredLanguage>y</PreferredLanguage>
         <Availability>y</Availability>
            <Property name="value">y</Property>
 </Person1>
  <Person2>
  <ContactType>Partner1</ContactType>
  <FirstName>x</FirstName>
  <LastName>x</LastName>
  <Salutation>x</Salutation>
  <Title>x</Title>
  <EmailAddress>x</EmailAddress>
  <TelephoneNumber>x</TelephoneNumber>
  <PreferredLanguage>x</PreferredLanguage>
  <Availability>x</Availability>
  <Property name="value">x</Property>
  </Person2>
  </Contacts>


But this code does not do this.

xercesc::DOMNode* node = findNode(szContactType, "ContactType"); // this is the node I want to delete


DOMNode* current = node->getFirstChild();
while (current != NULL)
{
      node->removeChild(current);
      current = node->getFirstChild();
}

But after the code is run the node and children are still in the XML file.

Here are some questions:
1) what is returned by the findNode method? The pointer to the DOMElement 'ContactType' or to its parent, 'Person1'? If the node returned is 'ContactType' you are removing the text node 'Partner', otherwise you are removing all the children of 'Person1', but in any case you are left with an empty element (e.g. in the first case <Person1><ContactType></ContactType><FirstName>y</FirstName>.... , in the second case <Person1></Person1>) 2) when you say "is still in the XML file", do you mean after you serialize back to disk using DOMWriter? Or are you expecting that by manipulating the DOM structure the XML file is automatically changed (it's not)?

Alberto



I would really appreciate some help, or even tell me if I am doing things correctly.

Thanks,
Enda


From: Mannion, Enda
Sent: 08 June 2006 10:00
To: c-dev@xerces.apache.org
Subject: RE: removeChild not working

Here is some more code using removeChild() that does not work for me.


xercesc::DOMNode* node = findNode(szContactType, "ContactType");
char* nodeName = XMLString::transcode(node->getNodeName());


DOMNode* current = node->getFirstChild();
while (current != NULL)
{
      char* nodeNa = XMLString::transcode(current->getNodeName());
      node->removeChild(current);
      current = node->getFirstChild();
}

I am currently using xerces 2_4, I have to remain using this version for a while, but I presume removeChild() worked in 2_4.


Any Ideas?

Enda


From: Mannion, Enda
Sent: 07 June 2006 20:40
To: c-dev@xerces.apache.org
Subject: removeChild not working

I want to remove the node below called outerNode but it is not working, any ideas.


xercesc::DOMNode* docNode = xmlDoc->getDocumentElement();

DOMNodeList* list = docNode->getChildNodes();
DOMNode* outerNode = NULL;

outerNode = list->item(i);

docNode->removeChild(outerNode);


Any ideas why?
Enda





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to