Solved

Updating Text Values Using XMLDOM

Posted on 2001-08-10
3
327 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 48

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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

615 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