- Home /
Get filename from XML instead of content
I'm looking for a way to compare the filename of an .xml-file to a bunch of strings in a dictionary. However, I can't seem to get the filename of the .xml, only it's content. I'm handling my .xml-files as XDocument. To illustrate my problem, please help me solve the following issue:
foreach (XDocument xml in MyDictionary){
Debug.Log ("Filename of xml is: " + ???);
}
What should I put instead of the question marks in order to log the filename of the .xml-file? Is some type of conversion necessary? Thanks in advance for any help or directions! :)
Answer by Bunny83 · Dec 01, 2017 at 02:14 AM
An XDocument only represents XML content. It has no relation to a file. How do you create your XDocument instances? Also How does your dictionary looks like? What's the key and what's the value?
If the dictionary is a Dictionary<string, XDocument>
and the key is a filename you may want to use
foreach(string key in MyDictionary.Keys)
Thank you for the clarification! I'll find another way to handle my .xml-files in my functions then, so I'll be able to retrieve it's filename or file path. Thanks for taking the time to answer my question!