Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XML DOM set node value

Reply
Thread Tools

XML DOM set node value

 
 
keepyourstupidspam
Guest
Posts: n/a
 
      11-08-2005
Hi,

I am using xerces dom C++, I want to change an element value, here is
the code I am using but the element in the file is not getting updated.

...
...
...
xercesc_2_4:OMDocument* xmlDoc = parser->getDocument();
xercesc:OMNodeList* list;
xercesc:OMNode* node;

list = xmlDoc->getElementsByTagName( XMLString::transcode(Key.c_str())
);
node = list->item(0);
if( xercesc:OMNode::ELEMENT_NODE == node->getNodeType() )
{
node->setNodeValue(XMLString::transcode(Value.c_str())) ;
}

Any help.


Thanks,
em

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      11-08-2005


keepyourstupidspam wrote:


> list = xmlDoc->getElementsByTagName( XMLString::transcode(Key.c_str())
> );
> node = list->item(0);
> if( xercesc:OMNode::ELEMENT_NODE == node->getNodeType() )
> {
> node->setNodeValue(XMLString::transcode(Value.c_str())) ;


In the DOM the node value of element nodes is supposed to be null and
you can't change that:
<http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1950641247>
It is not quite clear what you want to achieve, lots of people assume
the node value of an element node to be its text content thus if you
want to set the text content of the element then with DOM Level 3 (not
sure whether Xerces C supports that) you could do
node->setTextContent(XMLString::transcode(Value.c_str() ));
If you don't have DOM Level 3 then you need to remove all child nodes
and then add a new one with a text node, e.g. C++ pseudo code (not
tested/compiled!) could look alike
while (node->hasChildNodes()) {
node->removeChild(node->getLastChild());
}

node->appendChild(node->getOwnerDocument()->createTextNode(XMLString::transcode(Value.c_str() )));



--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
keepyourstupidspam
Guest
Posts: n/a
 
      11-08-2005
That didn't seem to work, but I will make it clearer what I am trying
to do.

Here is my XML

<MetaData>
<submissionID>12345</submissionID>
<SubmissionDate>Tue 11 08 15 33 05 2005</SubmissionDate>
<submissionType>Whatever</submissionType>
<description>Test Incident</description>
<currentState>Pending</currentState>
<annotations>Testing the data store manager</annotations>
<workflowID>0</workflowID>
<business>automobile</business>
<numAttachments>3</numAttachments>
<MetaData>

I just want ot change Pending to current in the <currentState> tag

em

 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      11-08-2005


keepyourstupidspam wrote:

> <currentState>Pending</currentState>


> I just want ot change Pending to current in the <currentState> tag


What I suggested (to remove all child nodes and insert a new text child
node) should work, as said the code was pseudo code as I don't use
Xerces C/C++ so you have to translate that into compilable C++ code
yourself.
If the element has exactly one text child node then it is easier, if you
have the element node then you can do
node->getFirstChild()->setNodeValue("current")
again pseudo code and you need to make sure you pass the Xerces DOM XML
string to setNodeValue and not a C string literal.
But the general approach described earlier is much safer as it works
whether that element has any child nodes or not or whether those child
nodes are text nodes or not.

There are also mailing list for users of specific Apache products thus
if you look at http://xml.apache.org/ for a Xerces C user mailing list
and post there then you are more likely to find someone to give you C++
code and not some generic DOM pseudo code.

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl variable $node/text() but $node can non-node-set help! Tjerk Wolterink XML 2 08-24-2006 03:28 AM
How to set the node indent property between the parent node and the leaf node viveknatani@gmail.com ASP .Net 0 02-13-2006 07:11 PM
how to create a node set of elements through C++ code while executing a style sheet and process the created node set. pvssvikas@gmail.com XML 0 01-25-2006 12:48 PM
XML DOM: XML/XHTML inside a text node noahlt@gmail.com Python 5 11-04-2005 07:45 PM
[HELP] Create a DOM using a node from another node yio@free.fr Java 0 07-16-2003 12:30 PM



Advertisments