Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 330
  • Last Modified:

Updating Text Values Using XMLDOM

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
Martin Liss
Asked:
Martin Liss
1 Solution
 
Dave_GreeneCommented:
'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
 
Martin LissRetired ProgrammerAuthor Commented:
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
 
sethu_mCommented:
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now