Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Help needed with c# and XML

Options
  • 01-04-2008 6:37pm
    #1
    Closed Accounts Posts: 999 ✭✭✭


    Hi,

    I'm updating an XML file using a small C# program the problem i'm having is that after i've made an update and saved the file the format of the XML file is changing.
    Originally like this
    <tu> 
    <tuv lang="EN-US">
    <seg>4) Click on &quot;Verify Email&quot;</seg>
    </tuv>
    <tuv lang="SV-SE">
    <seg>4) Klicka p&#229; &quot;Verify Email&quot;</seg>
    </tuv>
    </tu>
    
    but ends like this
        <tu> 
          <tuv lang="EN-US">
            <seg>4) Click on "Verify Email"</seg>
          </tuv>
          <tuv lang="SV-SE">
            <seg>4) Klicka p&#229; "Verify Email"</seg>
          </tuv>
        </tu>
    
    I'm using a XmlDocumnet to open the XML file. I fill a XMLNodeList with GetElementsByTagName("tag name") and then loop through the list looking for what i want.

    Is there a way to trim leading white space from before a XML tag in an entire file?

    Thanks for any help.


Comments

  • Registered Users Posts: 981 ✭✭✭fasty


    What are you using to write the XML file after the update?

    If you're using and XmlTextWriter, it's got a Settings property that gives you an XmlWriterSettings object. It has a property called Indent that which you can set to false.


  • Registered Users Posts: 2,494 ✭✭✭kayos


    I think the fact the quotes are not getting encoded would be more of a problem that the indents. Unless of course you are really worried about file size.

    How are you writing the file?


  • Closed Accounts Posts: 999 ✭✭✭Noelie


    Thanks for the help guys.
    Fasty, I wasn't using the XmlTextWrite, i was overwriting the XmlNodelist and then saving the file.

    I ended up just writing a function to read the file back in once the process was complete and i would trim the leading space. I them wrote another funtion that would convert the quotes back to html entities, however currenty it will only work for quotes and apostrifies at the moment

    I don't think the additional space would have had an effect on the file i'm just being a little paranoid so want the output to be identical to the input.

    thanks for the replies anyway.


Advertisement