473,394 Members | 1,879 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,394 software developers and data experts.

Problem with replaceData method...

I need some clarification on the proper usage of XML DOM (and perhaps XML itself) as I'm a bit of a noob when it comes to XML manipulation.

The replaceData is giving strange results. Essentially it will only replace EXISTING data. It will not replace a null value.

I have an XML document that looks like this:

Expand|Select|Wrap|Line Numbers
  1. <hwAssetUserField1 type="attrib">67671</hwAssetUserField1>
  2. <hwAssetUserField2 type="attrib"></hwAssetUserField2>
  3. <hwAssetUserField3 type="attrib"></hwAssetUserField3>
  4. <hwAssetUserField4 type="attrib"></hwAssetUserField4>
  5. <hwAssetUserField5 type="attrib">34</hwAssetUserField5>
  6.  
The following code (written in kix but I can duplicate this problem in VBScript as well)...
Expand|Select|Wrap|Line Numbers
  1. $XMLFile="Test.xml"
  2. If $xmlDoc.load($XMLFile)
  3. $XMLWriteLen = 9999
  4. $xmlDoc.getElementsByTagName("hwAssetUserField1").Item(0).firstChild.replaceData(0,$XMLWriteLen,"67671")
  5. $xmlDoc.getElementsByTagName("hwAssetUserField2").Item(0).firstChild.replaceData(0,$XMLWriteLen,"72")
  6. $xmlDoc.getElementsByTagName("hwAssetUserField3").Item(0).firstChild.replaceData(0,$XMLWriteLen,"72")
  7. $xmlDoc.getElementsByTagName("hwAssetUserField4").Item(0).firstChild.replaceData(0,$XMLWriteLen,"72")
  8. $xmlDoc.getElementsByTagName("hwAssetUserField5").Item(0).firstChild.replaceData(0,$XMLWriteLen,"72")
  9. $xmlDoc.Save($XMLFile)     
  10.  
My resulting XML ends up with fields 1 and 5 having data. The other fields are blank. I've tried appenddata and insert data as well, but that doesn't work.

What should I be doing differently?
Sep 7 '07 #1
1 1741
jkmyoung
2,057 Expert 2GB
instead of using .firstChild, try using .textContent eg

Expand|Select|Wrap|Line Numbers
  1. $XMLFile="Test.xml"
  2. If $xmlDoc.load($XMLFile)
  3. $XMLWriteLen = 9999
  4. $xmlDoc.getElementsByTagName("hwAssetUserField1").Item(0).textContent = "67671"
  5. $xmlDoc.getElementsByTagName("hwAssetUserField2").Item(0).textContent = "72"
  6. $xmlDoc.getElementsByTagName("hwAssetUserField3").Item(0).textContent = "72"
  7. $xmlDoc.getElementsByTagName("hwAssetUserField4").Item(0).textContent = "72"
  8. $xmlDoc.getElementsByTagName("hwAssetUserField5").Item(0).textContent = "72"
  9. $xmlDoc.Save($XMLFile)
Sep 14 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
6
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any...
10
by: Markus Svilans | last post by:
Hi, I have a weird problem in a virtual method. The original method code raises an access violation when it is run. The solution to the problem is to declare a dummy integer inside the virtual...
4
by: amidzic.branko | last post by:
I'm trying to solve a problem using inheritance and polymorphism in python 2.4.2 I think it's easier to explain the problem using simple example: class shortList:
7
xNephilimx
by: xNephilimx | last post by:
lHi guys! I'm having a little problem that's getting on my nerves, I couldn't find a solution, I also tryed googling it and I found nothing... (my field of expertise is in AS 2 and 3, but I still...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.