Click here to Skip to main content
15,881,173 members
Home / Discussions / C#
   

C#

 
GeneralRe: Same EXE vs Different EXE Pin
Bernhard Hiller7-Aug-14 21:11
Bernhard Hiller7-Aug-14 21:11 
AnswerRe: Same EXE vs Different EXE Pin
Akhil Mittal7-Aug-14 20:05
professionalAkhil Mittal7-Aug-14 20:05 
QuestionCall a SAP transaction, execute with given parameters and download a report with C# Pin
Goliadkin6-Aug-14 16:41
Goliadkin6-Aug-14 16:41 
AnswerRe: Call a SAP transaction, execute with given parameters and download a report with C# Pin
Goliadkin7-Aug-14 15:07
Goliadkin7-Aug-14 15:07 
QuestionXML usage Pin
eblaschka6-Aug-14 14:26
eblaschka6-Aug-14 14:26 
AnswerRe: XML usage Pin
Dave Kreskowiak6-Aug-14 17:08
mveDave Kreskowiak6-Aug-14 17:08 
AnswerRe: XML usage Pin
Bernhard Hiller6-Aug-14 20:49
Bernhard Hiller6-Aug-14 20:49 
AnswerRe: XML usage Pin
Richard Deeming7-Aug-14 1:35
mveRichard Deeming7-Aug-14 1:35 
Assuming you're just looking to get a list of the full paths of all the <File> elements, then LINQ makes this reasonably simple:

C#
static string GetFullPath(XElement fileElement)
{
    var names = new HashSet<XName> { "Drive", "Folder", "File" };
    
    IEnumerable<string> pathParts = fileElements.AncestorsAndSelf()
        .Where(el => names.Contains(el.Name))
        .Select(el => (string)el.Element("Name"))
        .Reverse();
    
    return string.Join("\\", pathParts);
}

...

const string xml = @"<Drive>
    <Name>C:</Name>
    <ContainedFolders>
        <Folder>
            <Name>Program Files</Name>
            <ContainedFolders>
                <Folder>
                    <Name>VirtualBox</Name>
                    <ContainedFolders>
                        <Folder>
                            <Name>Test</Name>
                            <ContainedFiles>
                                <File>
                                    <Name>qtaccessiblewidgets4.dll</Name>
                                </File>
                            </ContainedFiles>
                        </Folder>
                    </ContainedFolders>
                </Folder>
            </ContainedFolders>
        </Folder>
    </ContainedFolders>
</Drive>";


XDocument document = XDocument.Parse(xml);
IList<string> filePaths = document.Descendants("File").Select(GetFullPath).ToList();


LINQ[^]
LINQ to XML[^]



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: XML usage Pin
eblaschka10-Aug-14 11:39
eblaschka10-Aug-14 11:39 
GeneralRe: XML usage Pin
Richard Deeming11-Aug-14 1:53
mveRichard Deeming11-Aug-14 1:53 
GeneralRe: XML usage Pin
eblaschka12-Aug-14 4:42
eblaschka12-Aug-14 4:42 
GeneralRe: XML usage Pin
eblaschka12-Aug-14 11:14
eblaschka12-Aug-14 11:14 
AnswerThank you! Pin
eblaschka7-Aug-14 13:03
eblaschka7-Aug-14 13:03 
GeneralRe: Thank you! Pin
Dave Kreskowiak7-Aug-14 16:51
mveDave Kreskowiak7-Aug-14 16:51 
AnswerThank you! Pin
eblaschka7-Aug-14 15:49
eblaschka7-Aug-14 15:49 
GeneralRe: Thank you! Pin
Richard Deeming8-Aug-14 2:09
mveRichard Deeming8-Aug-14 2:09 
AnswerRe: XML usage Pin
PIEBALDconsult7-Aug-14 16:43
mvePIEBALDconsult7-Aug-14 16:43 
QuestionSend Email Notifications from Server Pin
Jassim Rahma6-Aug-14 11:28
Jassim Rahma6-Aug-14 11:28 
AnswerRe: Send Email Notifications from Server Pin
Bernhard Hiller6-Aug-14 20:54
Bernhard Hiller6-Aug-14 20:54 
GeneralRe: Send Email Notifications from Server Pin
Jassim Rahma10-Aug-14 10:19
Jassim Rahma10-Aug-14 10:19 
GeneralRe: Send Email Notifications from Server Pin
Bernhard Hiller10-Aug-14 20:06
Bernhard Hiller10-Aug-14 20:06 
Question.net framework Pin
Member 109952356-Aug-14 1:07
Member 109952356-Aug-14 1:07 
AnswerRe: .net framework PinPopular
Pete O'Hanlon6-Aug-14 1:09
mvePete O'Hanlon6-Aug-14 1:09 
GeneralRe: .net framework Pin
Joe Woodbury6-Aug-14 14:00
professionalJoe Woodbury6-Aug-14 14:00 
AnswerRe: .net framework Pin
Akhil Mittal6-Aug-14 20:07
professionalAkhil Mittal6-Aug-14 20:07 

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.