Click here to Skip to main content
16,007,071 members
Home / Discussions / C#
   

C#

 
AnswerRe: Recursion to find an XML element Pin
Not Active30-Dec-08 15:55
mentorNot Active30-Dec-08 15:55 
GeneralRe: Recursion to find an XML element Pin
Steven D. Foster30-Dec-08 16:12
Steven D. Foster30-Dec-08 16:12 
GeneralRe: Recursion to find an XML element Pin
Not Active30-Dec-08 16:33
mentorNot Active30-Dec-08 16:33 
GeneralRe: Recursion to find an XML element Pin
Steven D. Foster31-Dec-08 4:14
Steven D. Foster31-Dec-08 4:14 
AnswerRe: Recursion to find an XML element Pin
Steven D. Foster30-Dec-08 16:55
Steven D. Foster30-Dec-08 16:55 
AnswerRe: Recursion to find an XML element Pin
Christian Graus30-Dec-08 18:01
protectorChristian Graus30-Dec-08 18:01 
GeneralRe: Recursion to find an XML element Pin
Steven D. Foster31-Dec-08 4:07
Steven D. Foster31-Dec-08 4:07 
AnswerRecursion = BAD to find an XML element Pin
Steven D. Foster31-Dec-08 4:45
Steven D. Foster31-Dec-08 4:45 
This is a much easier way using XPath expression queries.

internal class Program
{
    private const string FILENAME = "Testfile.xml";
    private static readonly string[] SectionNames = new[] { "Schema" };
    private static readonly string[] ConfigItems = new[] { "SqlConnection", "Output" };

    private static void OutputNavigatorData(XPathNavigator navigator)
    {
        Console.WriteLine(navigator.Name);
        if (navigator.MoveToFirstAttribute())
        {
            Console.WriteLine(" - " + navigator.Name + " : " + navigator.Value);
            while (navigator.MoveToNextAttribute())
            {
                Console.WriteLine(" - " + navigator.Name + " : " + navigator.Value);
            }
        }
    }

    private static void Main(string[] args)
    {

        XmlDocument xmlDocument = new XmlDocument();
        xmlDocument.Load(FILENAME);

        XPathDocument doc = new XPathDocument(FILENAME);
        XPathNavigator nav = doc.CreateNavigator();

        foreach (var sSectionName in SectionNames)
        {
            foreach (var sConfigItem in ConfigItems)
            {
                XPathExpression expression = nav.Compile("//" + sSectionName + "/" + sConfigItem);
                XPathNodeIterator iterator = nav.Select(expression);
                while (iterator.MoveNext())
                {
                    OutputNavigatorData(iterator.Current);
                }
            }
        }
    }
}

QuestionHow do i go about this... do i create a DataBind / DataSet ??? [modified] Pin
cobalt-rose30-Dec-08 12:02
cobalt-rose30-Dec-08 12:02 
AnswerRe: How do i go about this... do i create a DataBind / DataSet ??? Pin
Not Active30-Dec-08 13:23
mentorNot Active30-Dec-08 13:23 
AnswerRe: How do i go about this... do i create a DataBind / DataSet ??? Pin
Mycroft Holmes30-Dec-08 14:45
professionalMycroft Holmes30-Dec-08 14:45 
GeneralRe: How do i go about this... do i create a DataBind / DataSet ??? Pin
cobalt-rose1-Jan-09 13:25
cobalt-rose1-Jan-09 13:25 
QuestionApp.config Pin
s196675m30-Dec-08 11:34
s196675m30-Dec-08 11:34 
AnswerRe: App.config Pin
vaghelabhavesh30-Dec-08 13:08
vaghelabhavesh30-Dec-08 13:08 
QuestionDesign time collection problem Pin
kanchoette30-Dec-08 10:16
kanchoette30-Dec-08 10:16 
AnswerRe: Design time collection problem Pin
Wendelius30-Dec-08 10:44
mentorWendelius30-Dec-08 10:44 
GeneralRe: Design time collection problem Pin
kanchoette30-Dec-08 11:28
kanchoette30-Dec-08 11:28 
GeneralRe: Design time collection problem Pin
Wendelius30-Dec-08 11:41
mentorWendelius30-Dec-08 11:41 
GeneralRe: Design time collection problem Pin
kanchoette30-Dec-08 11:51
kanchoette30-Dec-08 11:51 
GeneralRe: Design time collection problem Pin
Wendelius30-Dec-08 11:56
mentorWendelius30-Dec-08 11:56 
QuestionReceiving Email prob using c# Pin
Abdul Rahman Hamidy30-Dec-08 9:20
Abdul Rahman Hamidy30-Dec-08 9:20 
AnswerRe: Receiving Email prob using c# Pin
EliottA30-Dec-08 14:27
EliottA30-Dec-08 14:27 
GeneralRe: Receiving Email prob using c# Pin
Abdul Rahman Hamidy30-Dec-08 15:05
Abdul Rahman Hamidy30-Dec-08 15:05 
GeneralRe: Receiving Email prob using c# Pin
Christian Graus30-Dec-08 18:02
protectorChristian Graus30-Dec-08 18:02 
GeneralRe: Receiving Email prob using c# Pin
Abdul Rahman Hamidy30-Dec-08 18:44
Abdul Rahman Hamidy30-Dec-08 18:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.