473,614 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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::DO MDocument* xmlDoc = parser->getDocument( );
xercesc::DOMNod eList* list;
xercesc::DOMNod e* node;

list = xmlDoc->getElementsByT agName( XMLString::tran scode(Key.c_str ())
);
node = list->item(0);
if( xercesc::DOMNod e::ELEMENT_NODE == node->getNodeType( ) )
{
node->setNodeValue(X MLString::trans code(Value.c_st r()));
}

Any help.
Thanks,
em

Nov 8 '05 #1
3 4047


keepyourstupids pam wrote:

list = xmlDoc->getElementsByT agName( XMLString::tran scode(Key.c_str ())
);
node = list->item(0);
if( xercesc::DOMNod e::ELEMENT_NODE == node->getNodeType( ) )
{
node->setNodeValue(X MLString::trans code(Value.c_st r()));


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::tra nscode(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(no de->getLastChild() );
}

node->appendChild(no de->getOwnerDocume nt()->createTextNode (XMLString::tra nscode(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>1 2345</submissionID>
<SubmissionDate >Tue 11 08 15 33 05 2005</SubmissionDate>
<submissionType >Whatever</submissionType>
<description>Te st Incident</description>
<currentState>P ending</currentState>
<annotations>Te sting the data store manager</annotations>
<workflowID>0 </workflowID>
<business>autom obile</business>
<numAttachments >3</numAttachments>
<MetaData>

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

em

Nov 8 '05 #3


keepyourstupids pam wrote:
<currentState>P ending</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
3142
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 since they're not used anymore. But now, I used an <xsl:apply-templates/> and for some reason, it works in some situation but not in others. I didn't put the whole XSL file since it's quite big. Here's the part that bugs
6
2740
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 2003 - Windows XP Pro PC suscessfully. But when I ran it from the command line - C:\Documents and Settings\SHC\My Documents\Visual Studio Projects\XMLdtdValidatingReader\Debug>XMLdtdValidatingReader valcanoes.xml, I got the following message in...
2
7682
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 the VB I have? I also would like to use similar code to update the machine.config file so if someone could explain how to add a node ("appSettings") if node not found and also how to add a key value pair into the "appSettings" node if found I would...
5
1767
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> <StoredProc>spGetReconID</StoredProc> <Parms> <parm> <name>@tran</name> <value>956</value> </parm>
1
1785
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). anyhow, i'm just getting into .Net and am trying to parse a document, but not able to read the values for the nodes consistently. anybody know what i'm doing wrong? it seems that i'm able to console.writeLine the value of the node at the beginning of...
0
1175
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 like:XXXXXX=YYYYY==, but did I do wrong. Althouggh, I get the message, Satus as Success.Since, I have to use this SessionID in another click event on the same page, how do I do this.I tried, g_SessionID= loginDom.Value g_SessionID =...
0
1489
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), I see it has child nodes, but nodes = Nothing.. Since, I need to copy the value of SessionID in my next function, how can I read the value of Node. If I do, LoginDom.InnerText, then I get"SuccessSessionID", if there is no way to get node value...
1
2891
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 app.config file is listed below and the code is listed below that, the line with "-->>" is where i try to get the node. Can anyone see where I'm going wrong. A dump of the xmlDocument is listed below the code. Note: "MyKey" is set to "Reports"
0
3378
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 format every column with a color (e.g. red) if the element value is the same as the one in the next node. if the value changes if should change the color (e.g. to blue) and stay so long blue as the value is the same. With the next change, I should...
0
8182
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8627
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7093
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6088
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4052
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4127
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1425
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.