Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Editing Node of XML Document

Posted on 2006-06-27
3
Medium Priority
?
230 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses

704 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