Solved

Editing Node of XML Document

Posted on 2006-06-27
3
225 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
[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
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

752 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