Solved

Updating Text Values Using XMLDOM

Posted on 2001-08-10
3
320 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 45

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 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

20 Experts available now in Live!

Get 1:1 Help Now