473,322 Members | 1,566 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

XML DOM set node value

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::DOMDocument* xmlDoc = parser->getDocument();
xercesc::DOMNodeList* list;
xercesc::DOMNode* node;

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

Any help.
Thanks,
em

Nov 8 '05 #1
3 4022


keepyourstupidspam wrote:

list = xmlDoc->getElementsByTagName( XMLString::transcode(Key.c_str())
);
node = list->item(0);
if( xercesc::DOMNode::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/
Nov 8 '05 #2
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

Nov 8 '05 #3


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/
Nov 8 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Blaise Garant | last post by:
Hi I've made a stylesheet to transform my data into XSL-FO. This stylesheet used to work with MSXSL 4.0 but I've got some issues in ..NET. First, I changed removed all the "node-set()" function...
6
by: SHC | last post by:
Hi all, I created an application from the Console Application (.NET) of VC++ .NET 2003, and I did "Build" the application of the attached .cpp file, volcanoes.xml and geology.dtd on my VC++ .NET...
2
by: Keith M | last post by:
Hi, I have found a very useful piece of code in the msdn which shows how to load an xml config file, search for a particular value and replace it. Could someone possibly convert it to C# from...
5
by: Matt | last post by:
I need help with passing a generated node set from a style sheet into my customer msxsl extension. I have the following node set that I am creating: <xsl:variable name="sql"> <SQL>...
1
by: Dica | last post by:
hi all first off, i'm not trying to cross post, but couldn't find this newsgroup earlier (got here from a recommendation on microsoft.public.vb, where i originally posted this question). ...
0
by: XML newbie: Urgent pls help! | last post by:
ok, I changed "If node.Text = "Success" " to "If Not loginDom.InnerText Is Nothing ". Now, I don't get the NullReference error but the SessionID I see on screen is concatanated one. It looks...
0
by: XML newbie: Urgent pls help! | last post by:
HI, I am working on VB.Net.My program connects to the remote host, once the login values are verified, it sends the SessionID. My problem is Although in "Logindom" variable( in the Auto window),...
1
by: John Wilhelm | last post by:
I'm having a problem in by VB.net 2005 application. When i try to get a node from my app.config file the node come back with "nothing". The xmldocment loads OK, but I can't retrive a node. The...
0
by: HP17 | last post by:
Hi all, I am a bit desperate already trying to display a XML file using XSLT. I create a table and use <xsl:for-each> to extract every element node. This is working fine. What I want now is so...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.