Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 39549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:52:56+00:00 2026-05-10T14:52:56+00:00

I originally asked this question on RefactorMyCode , but got no responses there… Basically

  • 0

I originally asked this question on RefactorMyCode, but got no responses there…

Basically I’m just try to load an XmlNodeList into an XmlDocument and I was wondering if there’s a more efficient method than looping.

Private Function GetPreviousMonthsXml(ByVal months As Integer, ByVal startDate As Date, ByVal xDoc As XmlDocument, ByVal path As String, ByVal nodeName As String) As XmlDocument     '' build xpath string with list of months to return     Dim xp As New StringBuilder('//')     xp.Append(nodeName)     xp.Append('[')     For i As Integer = 0 To (months - 1)       '' get year and month portion of date for datestring       xp.Append('starts-with(@Id, '')       xp.Append(startDate.AddMonths(-i).ToString('yyyy-MM'))       If i < (months - 1) Then         xp.Append('') or ')       Else         xp.Append('')]')       End If     Next      '' *** This is the block that needs to be refactored ***     '' import nodelist into an xmldocument     Dim xnl As XmlNodeList = xDoc.SelectNodes(xp.ToString())     Dim returnXDoc As New XmlDocument(xDoc.NameTable)     returnXDoc = xDoc.Clone()     Dim nodeParents As XmlNodeList = returnXDoc.SelectNodes(path)     For Each nodeParent As XmlNode In nodeParents       For Each nodeToDelete As XmlNode In nodeParent.SelectNodes(nodeName)         nodeParent.RemoveChild(nodeToDelete)       Next     Next      For Each node As XmlNode In xnl       Dim newNode As XmlNode = returnXDoc.ImportNode(node, True)       returnXDoc.DocumentElement.SelectSingleNode('//' & node.ParentNode.Name & '[@Id='' & newNode.Attributes('Id').Value.Split('-')(0) & '']').AppendChild(newNode)     Next      '' *** end ***     Return returnXDoc End Function 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:52:57+00:00Added an answer on May 10, 2026 at 2:52 pm
    Dim returnXDoc As New XmlDocument(xDoc.NameTable) returnXDoc = xDoc.Clone() 

    The first line here is redundant – you are creating an instance of an XmlDocument, then reassigning the variable:

    Dim returnXDoc As XmlDocument = xDoc.Clone() 

    This does the same.

    Seeing as you appear to be inserting each XmlNode from your node list into a different place in the new XmlDocument then I can’t see how you could possibly do this any other way.

    There may be faster XPath expressions you could write, for example pre-pending an XPath expression with ‘//’ is almost always the slowest way to do something, especially if your XML is well structured. You haven’t shown your XML so I couldn’t really comment on this further however.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer To add the new group all you have to do… May 11, 2026 at 11:45 pm
  • Editorial Team
    Editorial Team added an answer Edit 3 New answer. I see these options: Post your… May 11, 2026 at 11:45 pm
  • Editorial Team
    Editorial Team added an answer Use the FieldInfo.FieldType to reflect over the type of the… May 11, 2026 at 11:45 pm

Related Questions

I originally asked this question on RefactorMyCode , but got no responses there... Basically
I originally asked this question , but in finding an answer, discovered that my
This question originally asked which is the best method for uploading files via SFTP
I've been teaching myself WPF through Sells/Griffiths' Programming WPF, and I've found it a
A couple of years ago the media was rife with all sorts of articles

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.