How To Deserialize xml File programically without System.Configuration












0















I have xml file with this code



<configuration>

<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>

<applicationSettings>
<GlobalERP.UI.Properties.Settings>
<setting name="SQLServerIP" serializeAs="String">
<value>192.168.1.1</value>
</setting>
<setting name="SQLUserName" serializeAs="String">
<value>sa</value>
</setting>
<setting name="SQLPassword" serializeAs="String">
<value>123</value>
</setting>
<setting name="SQLDBName" serializeAs="String">
<value />
</setting>
</GlobalERP.UI.Properties.Settings>
</applicationSettings>
</configuration>


How to deserialize and get value by name like "SQLServerIP" or "SQLUserName" by code and read lines without System.Configuration?










share|improve this question

























  • stackoverflow.com/questions/13043530/…

    – Mary
    Jan 19 at 6:32











  • by read all of string not use System.Configuration

    – xxxsenatorxxx
    Jan 19 at 6:35






  • 1





    That's not well-formed XML, try uploading it to xmlvalidation.com and you will get errors. That being said, if you just need to quickly parse some XML and pick out some values you can use LINQ to XML; see How does one parse XML files? or LINQ to read XML.

    – dbc
    Jan 19 at 6:43








  • 1





    @xxxsenatorxxx - which link? I posted two. Anyway, using LINQ to XML you can query deeply nested elements as shown in LINQ to XML extract nested elements, LINQ to XML nested elements query or Accessing nested elements while iterating an XML LINQ query?. Maybe you could provide a Minimal, Complete, and Verifiable example if those general answers aren't sufficient?

    – dbc
    Jan 19 at 7:42






  • 1





    And if you want to query a nested element based on an attribute value (here name="SQLServerIP" for instance) see LINQ to XML - Get element based on a nested elements value or Parsing XML Files in .NET.

    – dbc
    Jan 19 at 7:51
















0















I have xml file with this code



<configuration>

<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>

<applicationSettings>
<GlobalERP.UI.Properties.Settings>
<setting name="SQLServerIP" serializeAs="String">
<value>192.168.1.1</value>
</setting>
<setting name="SQLUserName" serializeAs="String">
<value>sa</value>
</setting>
<setting name="SQLPassword" serializeAs="String">
<value>123</value>
</setting>
<setting name="SQLDBName" serializeAs="String">
<value />
</setting>
</GlobalERP.UI.Properties.Settings>
</applicationSettings>
</configuration>


How to deserialize and get value by name like "SQLServerIP" or "SQLUserName" by code and read lines without System.Configuration?










share|improve this question

























  • stackoverflow.com/questions/13043530/…

    – Mary
    Jan 19 at 6:32











  • by read all of string not use System.Configuration

    – xxxsenatorxxx
    Jan 19 at 6:35






  • 1





    That's not well-formed XML, try uploading it to xmlvalidation.com and you will get errors. That being said, if you just need to quickly parse some XML and pick out some values you can use LINQ to XML; see How does one parse XML files? or LINQ to read XML.

    – dbc
    Jan 19 at 6:43








  • 1





    @xxxsenatorxxx - which link? I posted two. Anyway, using LINQ to XML you can query deeply nested elements as shown in LINQ to XML extract nested elements, LINQ to XML nested elements query or Accessing nested elements while iterating an XML LINQ query?. Maybe you could provide a Minimal, Complete, and Verifiable example if those general answers aren't sufficient?

    – dbc
    Jan 19 at 7:42






  • 1





    And if you want to query a nested element based on an attribute value (here name="SQLServerIP" for instance) see LINQ to XML - Get element based on a nested elements value or Parsing XML Files in .NET.

    – dbc
    Jan 19 at 7:51














0












0








0








I have xml file with this code



<configuration>

<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>

<applicationSettings>
<GlobalERP.UI.Properties.Settings>
<setting name="SQLServerIP" serializeAs="String">
<value>192.168.1.1</value>
</setting>
<setting name="SQLUserName" serializeAs="String">
<value>sa</value>
</setting>
<setting name="SQLPassword" serializeAs="String">
<value>123</value>
</setting>
<setting name="SQLDBName" serializeAs="String">
<value />
</setting>
</GlobalERP.UI.Properties.Settings>
</applicationSettings>
</configuration>


How to deserialize and get value by name like "SQLServerIP" or "SQLUserName" by code and read lines without System.Configuration?










share|improve this question
















I have xml file with this code



<configuration>

<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>

<applicationSettings>
<GlobalERP.UI.Properties.Settings>
<setting name="SQLServerIP" serializeAs="String">
<value>192.168.1.1</value>
</setting>
<setting name="SQLUserName" serializeAs="String">
<value>sa</value>
</setting>
<setting name="SQLPassword" serializeAs="String">
<value>123</value>
</setting>
<setting name="SQLDBName" serializeAs="String">
<value />
</setting>
</GlobalERP.UI.Properties.Settings>
</applicationSettings>
</configuration>


How to deserialize and get value by name like "SQLServerIP" or "SQLUserName" by code and read lines without System.Configuration?







c# xml






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 19 at 7:32









Manoj Choudhari

1,234215




1,234215










asked Jan 19 at 6:27









xxxsenatorxxxxxxsenatorxxx

479




479













  • stackoverflow.com/questions/13043530/…

    – Mary
    Jan 19 at 6:32











  • by read all of string not use System.Configuration

    – xxxsenatorxxx
    Jan 19 at 6:35






  • 1





    That's not well-formed XML, try uploading it to xmlvalidation.com and you will get errors. That being said, if you just need to quickly parse some XML and pick out some values you can use LINQ to XML; see How does one parse XML files? or LINQ to read XML.

    – dbc
    Jan 19 at 6:43








  • 1





    @xxxsenatorxxx - which link? I posted two. Anyway, using LINQ to XML you can query deeply nested elements as shown in LINQ to XML extract nested elements, LINQ to XML nested elements query or Accessing nested elements while iterating an XML LINQ query?. Maybe you could provide a Minimal, Complete, and Verifiable example if those general answers aren't sufficient?

    – dbc
    Jan 19 at 7:42






  • 1





    And if you want to query a nested element based on an attribute value (here name="SQLServerIP" for instance) see LINQ to XML - Get element based on a nested elements value or Parsing XML Files in .NET.

    – dbc
    Jan 19 at 7:51



















  • stackoverflow.com/questions/13043530/…

    – Mary
    Jan 19 at 6:32











  • by read all of string not use System.Configuration

    – xxxsenatorxxx
    Jan 19 at 6:35






  • 1





    That's not well-formed XML, try uploading it to xmlvalidation.com and you will get errors. That being said, if you just need to quickly parse some XML and pick out some values you can use LINQ to XML; see How does one parse XML files? or LINQ to read XML.

    – dbc
    Jan 19 at 6:43








  • 1





    @xxxsenatorxxx - which link? I posted two. Anyway, using LINQ to XML you can query deeply nested elements as shown in LINQ to XML extract nested elements, LINQ to XML nested elements query or Accessing nested elements while iterating an XML LINQ query?. Maybe you could provide a Minimal, Complete, and Verifiable example if those general answers aren't sufficient?

    – dbc
    Jan 19 at 7:42






  • 1





    And if you want to query a nested element based on an attribute value (here name="SQLServerIP" for instance) see LINQ to XML - Get element based on a nested elements value or Parsing XML Files in .NET.

    – dbc
    Jan 19 at 7:51

















stackoverflow.com/questions/13043530/…

– Mary
Jan 19 at 6:32





stackoverflow.com/questions/13043530/…

– Mary
Jan 19 at 6:32













by read all of string not use System.Configuration

– xxxsenatorxxx
Jan 19 at 6:35





by read all of string not use System.Configuration

– xxxsenatorxxx
Jan 19 at 6:35




1




1





That's not well-formed XML, try uploading it to xmlvalidation.com and you will get errors. That being said, if you just need to quickly parse some XML and pick out some values you can use LINQ to XML; see How does one parse XML files? or LINQ to read XML.

– dbc
Jan 19 at 6:43







That's not well-formed XML, try uploading it to xmlvalidation.com and you will get errors. That being said, if you just need to quickly parse some XML and pick out some values you can use LINQ to XML; see How does one parse XML files? or LINQ to read XML.

– dbc
Jan 19 at 6:43






1




1





@xxxsenatorxxx - which link? I posted two. Anyway, using LINQ to XML you can query deeply nested elements as shown in LINQ to XML extract nested elements, LINQ to XML nested elements query or Accessing nested elements while iterating an XML LINQ query?. Maybe you could provide a Minimal, Complete, and Verifiable example if those general answers aren't sufficient?

– dbc
Jan 19 at 7:42





@xxxsenatorxxx - which link? I posted two. Anyway, using LINQ to XML you can query deeply nested elements as shown in LINQ to XML extract nested elements, LINQ to XML nested elements query or Accessing nested elements while iterating an XML LINQ query?. Maybe you could provide a Minimal, Complete, and Verifiable example if those general answers aren't sufficient?

– dbc
Jan 19 at 7:42




1




1





And if you want to query a nested element based on an attribute value (here name="SQLServerIP" for instance) see LINQ to XML - Get element based on a nested elements value or Parsing XML Files in .NET.

– dbc
Jan 19 at 7:51





And if you want to query a nested element based on an attribute value (here name="SQLServerIP" for instance) see LINQ to XML - Get element based on a nested elements value or Parsing XML Files in .NET.

– dbc
Jan 19 at 7:51












1 Answer
1






active

oldest

votes


















0














I find Best
Answer
with an small edit



 XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNodeList elemList = doc.GetElementsByTagName("setting");
for (int i = 0; i < elemList.Count; i++)
{
if (elemList[i].Attributes["name"].Value == "UserName")
{
textBox1.Text += elemList[i].InnerText;
}
}





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54264638%2fhow-to-deserialize-xml-file-programically-without-system-configuration%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I find Best
    Answer
    with an small edit



     XmlDocument doc = new XmlDocument();
    doc.Load(path);
    XmlNodeList elemList = doc.GetElementsByTagName("setting");
    for (int i = 0; i < elemList.Count; i++)
    {
    if (elemList[i].Attributes["name"].Value == "UserName")
    {
    textBox1.Text += elemList[i].InnerText;
    }
    }





    share|improve this answer




























      0














      I find Best
      Answer
      with an small edit



       XmlDocument doc = new XmlDocument();
      doc.Load(path);
      XmlNodeList elemList = doc.GetElementsByTagName("setting");
      for (int i = 0; i < elemList.Count; i++)
      {
      if (elemList[i].Attributes["name"].Value == "UserName")
      {
      textBox1.Text += elemList[i].InnerText;
      }
      }





      share|improve this answer


























        0












        0








        0







        I find Best
        Answer
        with an small edit



         XmlDocument doc = new XmlDocument();
        doc.Load(path);
        XmlNodeList elemList = doc.GetElementsByTagName("setting");
        for (int i = 0; i < elemList.Count; i++)
        {
        if (elemList[i].Attributes["name"].Value == "UserName")
        {
        textBox1.Text += elemList[i].InnerText;
        }
        }





        share|improve this answer













        I find Best
        Answer
        with an small edit



         XmlDocument doc = new XmlDocument();
        doc.Load(path);
        XmlNodeList elemList = doc.GetElementsByTagName("setting");
        for (int i = 0; i < elemList.Count; i++)
        {
        if (elemList[i].Attributes["name"].Value == "UserName")
        {
        textBox1.Text += elemList[i].InnerText;
        }
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 19 at 9:07









        xxxsenatorxxxxxxsenatorxxx

        479




        479






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54264638%2fhow-to-deserialize-xml-file-programically-without-system-configuration%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Liquibase includeAll doesn't find base path

            How to use setInterval in EJS file?

            Petrus Granier-Deferre