Solved

Editing Node of XML Document

Posted on 2006-06-27
3
220 Views
Last Modified: 2010-08-05
Hello,
I have an XML Document that looks like the following. I am trying to find out how to add a value to the nodes below. For instance If I want to add 1999-01-01 to From Report Date and 1999-02-02 to To Report Date.

 <FromReportDate> </FromReportDate> and <ToReportDate></ToReportDate>

My 2nd question is, how to Replace and add a value if something is exsistent there. Lets says 1999-01-01 is in FromReportDate, I want it to replace 1999-01-01 and add whatever the new value is, instead of just adding to the exsisting value)
Something like

If  Value at FromReportDate
Then clear and add with textbox1.text
If no value at FromReportDate
then Add with textboxt1.text

Thanks!



<?xml version="1.0" ?>
<?qbxml version="5.0"?>
<QBXML>
<QBXMLMsgsRq onError = "continueOnError">
  <PayrollSummaryReportQueryRq>
    <PayrollSummaryReportType>PayrollSummary</PayrollSummaryReportType>
    <ReportPeriod>
      <FromReportDate></FromReportDate>
      <ToReportDate></ToReportDate>
      </ReportPeriod>
      

  </PayrollSummaryReportQueryRq>


 </QBXMLMsgsRq>
</QBXML>
0
Comment
Question by:JasonWinn
  • 2
3 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16995218
Assuming you have loaded your XML into a DOMDocument called oDom:

    Set oNode = oDom.selectSingleNode("//FromReportDate")
    If Not oNode Is Nothing Then
        oNode.Text = "1999-01-01"                           '// Replace existing text
        oNode.Text = oNode.Text & "1999-01-01"      '// Append to existing text
    End If
0
 
LVL 3

Author Comment

by:JasonWinn
ID: 16995285
Hey Carl_tawn,
Thanks for the quick reply. I am pretty new to VB so I am not quit sure how to load the DOMDocument.

Right now I just have   this:

        Dim xDoc As XmlDocument

        xDoc = New XmlDocument
        xDoc.Load("C:\Documents and Settings\payrollSummaryPrevious.xml")







        xDoc.Save("C:\Documents and Settings\payrollSummaryPrevious.xml")
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 16995325
Ah, you're using VB.Net rather than VB6.

What you have already creates an XmlDocument object and loads your XML file from disc. So, to modify the text of a node you would add something like:

        xDoc = New XmlDocument
        xDoc.Load("C:\Documents and Settings\payrollSummaryPrevious.xml")

        Dim node As XmlNode = xDoc.SelectSingleNode("//FromReportDate")
       
        node.InnerText = "1999-01-01"        '// Change the current text
        node.InnerText &= "1999-01-01"      '// Append to the current text

        xDoc.Save("C:\Documents and Settings\payrollSummaryPrevious.xml")
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 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

13 Experts available now in Live!

Get 1:1 Help Now