Hi,
Jairam, Roopnaraine wrote:
Alberto how do I fix the memory leak from the transcode.
You delete what is returned.
BTW forgot to mention that I'm a newbie just learning this stuff. As for the original problem I didn't write any code serializing the DOM back to disk. I thought by just calling setNodeValue that this would save the value passed to disk. Do you have any sample code or a link on how to do this. This would be much appreciated...
No, you are editing an in memory representation. Take a look at DOMWriter for serialization.
http://xml.apache.org/xerces-c/apiDocs/classDOMWriter.html
Gareth
Thanks
Vince.
-----Original Message----- *From:* Alberto Massari [mailto:[EMAIL PROTECTED] *Sent:* Sat 12/18/2004 7:27 AM *To:* [EMAIL PROTECTED] *Cc:* *Subject:* Re: setNodeValue() not working
Hi Vince, from a cursory look to your code, the new values should update the FirstName and LastName content (btw, you have a memory leak by using XMLString::transcode without releasing the returned string). One thing looks strange: you say "the file is not updated", but I don't see any code serializing the DOM back to disk. I hope you have written such code (otherwise the changes stay in memory): can you post it?
Alberto
At 17.11 17/12/2004 -0500, Jairam, Roopnaraine wrote:
>Hi:
>
>I trying to read and write to my xml file. I am able to read from
the file
>but when trying to update an element no errors are returned but
the file
>is not updated I have attached my code for the write please help
>
><LicenseSystem>
> <ContactInfo>
> <FirstName>abc</FirstName>
> <LastName>def</LastName>
> <Address1>my address</Address1>
> <Address2></Address2>
> <City>abc</City>
> <State>new york</State>
> <Zip1>12122</Zip1>
> <Zip2></Zip2>
> <Country>usa</Country>
> <Phone></Phone>
> <Email>[EMAIL PROTECTED]</Email>
> </ContactInfo>
>
>â.
><LicenseSystem>
>
>
>
>DWORD XML::parseFile()
>{
> if (m_parsed)
> return ERROR_SUCCESS;
> if (m_parser != NULL)
> {
> m_parser->parse(m_xmlFileName);
> m_document = m_parser->getDocument();
> if (m_document != NULL)
> {
> m_parsed = true;
> return ERROR_SUCCESS;
> }
> }
>
> return ERROR_INVALID_HANDLE;
>}
>
>DWORD XML::WriteUserInfo(PUSERINFO pUserInfo)
>{
> if (pUserInfo == NULL)
> return ERROR_NO_DATA;
>
> if (parseFile() != ERROR_SUCCESS)
> return ERROR_INVALID_HANDLE;
>
> DOMNodeList* contactInfo =
> m_document->getElementsByTagName(LâContactInfoâ);
>
> if (contactInfo == NULL)
> return ERROR_INVALID_HANDLE;
>
> DOMElement* element = (DOMElement
*)contactInfo->item( 0 );
>
> SetElementText(element, LâFirstNameâ,
pUserInfo->szFirstName);
> SetElementText(element, Lâ LastNameâ,
pUserInfo->szLastName);
> â
> return ERROR_SUCCESS;
>}
>
>
>// -----------------------------------------------
>DWORD XML::SetElementText(DOMElement *pElem, LPCWSTR pzName, LPCSTR value)
>{
> if( pElem != NULL )
> {
> DOMNodeList *pList = pElem->getElementsByTagName(pzName);
> if( pList->getLength() > 0 )
> {
> DOMElement *pElem = (DOMElement *)pList->item( 0 );
> DOMNode *pChild = pElem->getFirstChild();
>
> if( pChild )
> {
> pChild->setNodeValue(XMLString::transcode(value));
> return ERROR_SUCCESS;
> }
> }
> }
>
>
> return ERROR_INVALID_HANDLE;
>}
>
>Thanks vince.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
-- Gareth Reakes, Managing Director Parthenon Computing +44-1865-811184 http://www.parthcomp.com
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]