0

I have some trouble loading an XML File and turn it into string (like <XBoxIP></XBoxIP> and I want whats in between them); this is my xml file:

<?xml version="1-0" encoding="UTF8"?>
<Config>
    <XBoxIP></XBoxIP>
    <XBoxPort></XBoxPort>
    <XBoxUser></XBoxUser>
    <XBoxPassword></XBoxPassword>
    <XBoxSongPath></XBoxSongPath>
    <LocalSongPath></LocalSongPath>
</Config>

Or is my XML File maybe incorrect? Thanks for the help, i am new to C# and XML.

XmlDocument doc = new XmlDocument();
doc.Load(path + "/Config.xml");
string xmlcontents = doc.InnerXml;

is the code im currently using, and i don't really know what to do after that.

11
  • Please show the problematic code also Commented May 4, 2018 at 20:21
  • @RufusL XmlDocument doc = new XmlDocument(); doc.Load(path + "/Config.xml"); string xmlcontents = doc.InnerXml; and i don't know what to do after that :/ Commented May 4, 2018 at 20:23
  • Is your object serializable? Commented May 4, 2018 at 20:25
  • @random No, i don't think so. Commented May 4, 2018 at 20:26
  • 1
    On closer inspection, your XML is not valid or well-formed. Upload it to xmlvalidation.com and you will get an error XML version "1-0" is not supported, only XML 1.0 is supported. "1.0" and "1.1" are both recognized XML versions but "1-0" is not. See also dotnetfiddle.net/VK1aY0 that shows the same error with .Net. Commented May 4, 2018 at 21:28

1 Answer 1

0

I make slight change to your xml and i hope it will work for you.

<?xml version="1.0" encoding="UTF-8"?> //make changes here
<Config>
    <XBoxIP></XBoxIP>
    <XBoxPort></XBoxPort>
    <XBoxUser></XBoxUser>
    <XBoxPassword></XBoxPassword>
    <XBoxSongPath></XBoxSongPath>
    <LocalSongPath></LocalSongPath>
</Config>

you can also used below property. The OuterXml property returns a string version of the xml.

xmlDoc.OuterXml;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.