Solved

Updating Text Values Using XMLDOM

Posted on 2001-08-10
3
321 Views
Last Modified: 2008-02-01
Below is one node (of many) in an xml file. How would I go about changing the <texte>xyz</texte> to <texte>new value</texte>?

 
- <class name="Quote" abstract="no" version="1.0">
- <description>
- <text>
  <texte>xyz</texte>
  </text>
- <short-text>
  <texte>Quote</texte>
  </short-text>
  </description>
- <attribute name="quoteId" type="string" required="always" max-chars="10">
- <representation>
- <label>
- <text>
  <texte>Quote ID</texte>
  </text>
- <short-text>
  <texte>Quote ID</texte>
  </short-text>
  </label>
  </representation>
  </attribute>
- <attribute name="status" type="enum" value-type="string" required="always">
- <values>
- <value>
  <simple-value>initial</simple-value>
  </value>
- <value>
  <simple-value>finalized</simple-value>
  </value>
- <value>
  <simple-value>logged</simple-value>
  </value>
- <value>
  <simple-value>booked</simple-value>
  </value>
  </values>
- <value>
  <simple-value>initial</simple-value>
  </value>
  </attribute>
  <attribute name="items" type="collection" value-type="Switch" />
  <attribute name="pricing-reference" type="string" />
  <attribute name="customer-reference" type="string" />
  <attribute name="customer-name" type="string" />
  <attribute name="total-price" type="double" />
  <attribute name="sap-doc-number" type="string" />
  <attribute name="lastModified" type="date" />
  <attribute name="expirationDate" type="date" />
- <!--  only for now, change string to a reference later
  -->
  <attribute name="created-by" type="string" />
- <!--  added by Saif for Bottom Line Discount
  -->
  <attribute name="cost" type="double" required="always" />
  <attribute name="tax" type="double" required="always" />
  <attribute name="gp" type="double" required="always" />
- <!--  Total Installation List Price. Doesnt include adjustments and tax
  -->
  <attribute name="totalListPrice" type="double" required="always" />
- <!--  Total Installation List Price with adjustments. Doesnt include tax
  -->
  <attribute name="totalLabor" type="double" required="always" />
  <attribute name="totalAdjustedListPrice" type="double" required="always" />
  <attribute name="totalAdjListNoLabor" type="double" required="always" />
  <attribute name="conditions" type="collection" value-type="BottomLine" max="4" />
- <attribute name="description" type="string">
- <representation>
- <label>
- <text>
  <texte>Description</texte>
  </text>
- <short-text>
  <texte>Desc</texte>
  </short-text>
  </label>
  </representation>
  </attribute>
  </class>
0
Comment
Question by:Martin Liss
3 Comments
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6374577
'VB Example

Option Explicit

Dim oDOM      As DOMDocument
Dim oRoot     As IXMLDOMNode
Dim oNode     As IXMLDOMNode
Dim oUpdateNode as IXMLDOMNode

Private Sub Command1_Click()

Set oDOM = New DOMDocument
Dim i As Long

oDOM.Load "C:\test.xml"

Set oRoot = oDOM.selectSingleNode("text")

Set oNode = oRoot.selectSingleNode("texte")

Set oUpdateNode = oNode
oUpdateNode.Attributes.getNamedItem("EMAIL").Text = strNewVALUE  'your new value here

oRoot.replaceChild oUpdateNode, oNode   'swap nodes

Set oDOM = Nothing
Set oNode = Nothing
Set oUpdateNode = Nothing
End Sub
0
 
LVL 46

Author Comment

by:Martin Liss
ID: 6374782
Thanks for the reply, but there's a problem.

In my app the dom document is called XMLDoc, the xml is already loaded and gxml.NodeName is a property that carries in this case "Quote", so here is the code that I tried to use:

Dim oRoot     As IXMLDOMNode
Dim oNode     As IXMLDOMNode
Dim oUpdateNode As IXMLDOMNode

Set oRoot = XMLDoc.selectSingleNode("class[@name='" & gxml.NodeName _
                   & "']//description/text") 'oDOM.selectSingleNode("text")

Set oNode = oRoot.selectSingleNode("texte")

Set oUpdateNode = oNode
oUpdateNode.Attributes.getNamedItem("text").Text = strNewVALUE  'your new value here

oRoot.replaceChild oUpdateNode, oNode   'swap nodes


The first problem is that while I get no error after the Set oRoot... statement, no matter how I reference oRoot I get an error 91 "Object variable... not set" error. The other problem is that I'm not sure what I should put between the quots in the oUpdateNode... statement.

0
 
LVL 1

Accepted Solution

by:
sethu_m earned 50 total points
ID: 6375109
Hello,

U can directly assign the new value with this single
statement itself.

XMLDoc.selectSingleNode("//class[@name='" & gxml.NodeName & "']//description/text/texte").text = 'NewValue'

No need of using another node, then changing the values. I think its a long way to get the thing done.

Hope this works for u.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now