I want to get a Element from a XML File. But I don’t know how I get a Element from The XML.
My XML File:
<?xml version="1.0" standalone="yes" ?>
<NewDataSet>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="resources">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:string" minOccurs="0" />
<xs:element name="text" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<resources>
<id>id_SearchUser</id> <!--Label lblSearchUser-->
<text>Benutzer</text>
</resources>
<resources>
<id>id_location</id> <!--Label lblLocation-->
<text>Werk</text>
</resources>
<resources>
<id>id_Search</id> <!--Button Button2-->
<text>Suchen</text>
</resources>
<resources>
<id>id_User</id> <!--Label lblUser-->
<text>Benutzer</text>
</resources>
<resources>
<id>id_eMail</id> <!-- Label lblEmail-->
<text>eMail</text>
</resources>
<resources>
<id>id_Firstname</id> <!--LinkLabel lnkFirstname-->
<text>Vorname</text>
</resources>
<resources>
<id>id_Lastname</id> <!--LinkLabel lnkLastname-->
<text>Nachname</text>
</resources>
<resources>
<id>id_Telephonnumber</id> <!--Label lblTelephon-->
<text>Telefon</text>
</resources>
</NewDataSet>
My Idea:
I get the location of a User. For Example “de” and than I want to call the GetXMLElement Method that give me the Content of a Element.
For Example:
I have a Label in my Application “id_SearchUser” and I want that this text property change to the Content of the …
…
<resources>
<id>id_SearchUser</id>
<text>Benutzer</text>
</resources>
….
and the Text is than Benutzer.
My Method:
public string GetXMLElement()
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("~/App_Data/de_language.xml"));
XmlNode node = // ??
return // node as string
}
What about this?
Notice that I used
XDocumentinstead of yourXmlDocument, XDocument uses LINQ whereas XmlDocument uses XPATH to get nodes. It’s a matter of preference.