Solved

Editing Node of XML Document

Posted on 2006-06-27
3
223 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

786 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