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 8851935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:16:43+00:00 2026-06-14T13:16:43+00:00

I have a sub that im trying to use to get some XML out

  • 0

I have a sub that im trying to use to get some XML out put, but no matter what I do the output file writes everything on the same line : Here is my code below, can you advice me on where I might be goign wrong ?

 Private Sub CreateActionFile()

        Dim lobjDirectory As New DirectoryInfo(mstrFolderName)
        Dim lobjFiles As New List(Of FileInfo)
        lobjFiles.AddRange(lobjDirectory.GetFiles("*.xml"))
        Dim lobjWriter As XmlWriter = XmlWriter.Create(mstrFolderName & "\" & txtActionName.Text & ".xml")

        Dim lobjSettings As New XmlWriterSettings()

        lobjSettings.Indent = True
        lobjSettings.NewLineOnAttributes = True

        Dim lstrStartFileNumber As Integer = CInt(txtFrom.Text)
        Dim lstrEndFileNumber As Integer = CInt(txtTo.Text)

        lobjWriter.WriteStartElement("Action")
        lobjWriter.WriteAttributeString("ID", Me.txtID.Text)
        lobjWriter.WriteAttributeString("Name", Me.txtActionName.Text)
        lobjWriter.WriteAttributeString("Type", "XML")
        lobjWriter.WriteStartElement("xml")
        While lstrEndFileNumber > lstrStartFileNumber
            For Each lobjFile As FileInfo In lobjFiles
                If lobjFile.Name.StartsWith(lstrStartFileNumber.ToString) Then
                    Dim lobjXmlDom As New XmlDocument
                    lobjXmlDom.Load(lobjFile.FullName)
                    lobjXmlDom.WriteContentTo(lobjWriter)
                    lstrStartFileNumber = lstrStartFileNumber + 1
                Else
                    'Nothing - move on
                End If
            Next
        End While
        lobjWriter.WriteEndElement()
        lobjWriter.WriteEndElement()
        lobjWriter.WriteEndDocument()

        lobjWriter.Close()

    End Sub
  • 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. Editorial Team
    Editorial Team
    2026-06-14T13:16:44+00:00Added an answer on June 14, 2026 at 1:16 pm

    You’re creating the settings, but then not passing them to anything:

    Dim lobjSettings As New XmlWriterSettings()
    lobjSettings.Indent = True
    lobjSettings.NewLineOnAttributes = True
    

    You should use them when you create the XmlWriter:

    Dim filename = Path.Combine(mstrFolderName, txtActionName.Text & ".xml")
    Dim lobjWriter = XmlWriter.Create(filename, lobjSettings)
    

    (I’ve separated out the filename from the writer creation just for formatting, but please note the use of Path.Combine as well.)

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

Sidebar

Related Questions

I'm trying to use annotate but have a problem: The output ignores some information
So I have some perl code that goes something like: use strict; use XML::XPath;
i have a file, filedata.mat, containing a 1x1 struct with sub-levels that contain data
i'm trying to use a regexp to arrange some text, with re.sub . Let's
I have some code where I am trying to use variables in a tabpage.
I have seen some SO users run into an issue when trying to use
In a module i have a sub that create modalpopup and show result of
I have a sub query that returns one column, showing as GroupType, I then
I have a sub form that looks like a datasheet view. It returns prices
We have a sub-project 'commonUtils' that has many generic code-snippets used across the parent

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.