C# XmlDocument SelectNodes nicht funktioniert
Ich möchte den Wert aus der XML-Datei, aber ich konnte nicht. Können Sie mir bitte helfen, das problem ?? Da ich schon sehr hart versucht, zu testen und googeln aber ich habe immer noch das problem aber nicht finden.
XML :
<?xml version="1.0" encoding="utf-8" ?>
<Contacts>
- <Contact>
<ID>xxx</ID>
<AutoUpdateEnabled>false</AutoUpdateEnabled>
<LastChanged>2013-05-29T01:53:59.4470000Z</LastChanged>
- <Profiles>
- <Personal>
<FirstName>My First Name</FirstName>
<LastName>My Last Name</LastName>
<UniqueName>My Unique Name</UniqueName>
<SortName></SortName>
<DisplayName>My Display Name</DisplayName>
</Personal>
</Profiles>
- <Phones>
- <Phone>
<ID>3</ID>
<PhoneType>Mobile</PhoneType>
<Number>000-0000000</Number>
<IsIMEnabled>false</IsIMEnabled>
<IsDefault>false</IsDefault>
</Phone>
</Phones>
- <Locations>
- <Location>
<ID>2</ID>
<LocationType>Business</LocationType>
<CompanyName></CompanyName>
<IsDefault>false</IsDefault>
</Location>
</Locations>
</Contact>
- <Contact>
<ID>xxx</ID>
<AutoUpdateEnabled>false</AutoUpdateEnabled>
<LastChanged>2013-05-29T01:53:25.2670000Z</LastChanged>
- <Profiles>
- <Personal>
<FirstName>Person</FirstName>
<LastName>Two</LastName>
<UniqueName></UniqueName>
<SortName></SortName>
<DisplayName>Person Two</DisplayName>
</Personal>
</Profiles>
- <Emails>
- <Email>
<ID>1</ID>
<EmailType>Personal</EmailType>
<Address>[email protected]</Address>
<IsIMEnabled>false</IsIMEnabled>
<IsDefault>true</IsDefault>
</Email>
</Emails>
- <Locations>
- <Location>
<ID>2</ID>
<LocationType>Business</LocationType>
<CompanyName>Testing Company</CompanyName>
<IsDefault>false</IsDefault>
</Location>
</Locations>
</Contact>
</Contacts>
Mein Beispiel-Code :
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml("TheXMLFile.xml");
xmldoc.DocumentElement.SelectNodes("contact") //return 0 counts
xmldoc.DocumentElement.SelectNodes("/contact") //return 0 counts
xmldoc.DocumentElement.SelectNodes("/contact") //return 0 counts
xmldoc.DocumentElement.SelectNodes("/contacts/contact") //return 0 counts
xmldoc.DocumentElement.SelectNodes("*") //return 2 counts !this works
XmlNodeList elemList = xmldoc.DocumentElement.GetElementsByTagName("contact"); //return 2 counts !this also works
foreach (XmlNode node in elemList)
{
node.SelectSingleNode("Profiles") //return ""
node.SelectSingleNode("/Profiles") //return ""
node.SelectSingleNode("//Profiles") //return ""
node.SelectSingleNode(".//Profiles") //return ""
}
Ich will einfach nur, um "Vorname, Nachname, E-Mail-Adresse", die SelectNodes
Funktion einfach nicht funktioniert wie erwartet... Keine Ahnung ... bitte um Hilfe. Vielen Dank im Voraus
Du musst angemeldet sein, um einen Kommentar abzugeben.
Müssen Sie so etwas wie dieses:
Mit diesem Ansatz, sollten Sie in der Lage zu Lesen alle Daten, die Sie brauchen, richtig.
Die XML-tags sind vom Einzelfall abhängig, so Kontaktieren != Kontakt.
Ändern Sie diese für einen start.
Das Problem ist, dass der SelectNodes-Methode nimmt einen XPath-Ausdruck, der groß-und Kleinschreibung.
Im code oben sehen Sie 2 Vornamen, "Mein Vorname" und "Person". Ich habe gerade die ersten Zeichen zu Großbuchstaben "Kontakt" -> "Kontakt".