Solved

Updating Text Values Using XMLDOM

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with SimpleXML charts with PHP 4 101
Strange html entity encoding by tidy 14 95
XML XSLT If loop 4 31
xpath sql query 2008 8 58
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…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

820 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