2011-12-10 17 views
0

Iは、以下に示すように、サンプルXML要素に基づいてXMLノードを読み取っていますか?

<UserSettings> 
    <Source>settings/subscriptions</Source> 
    <DestinationController>UserSettings</DestinationController> 
    <DestinationAction>GetUserPreferenceSettings</DestinationAction> 
</UserSettings> 

は、タグ名(UserSettings)を使用してXMLの読み取りが行われています。

XmlDataDocument xmlDoc = new XmlDataDocument(); 
strFileName = System.Configuration.ConfigurationManager.AppSettings["UrlRoutingPath"].ToString(); 
strFileLocation = HttpContext.Current.Server.MapPath("~/" + strFileName); 

xmlDoc.Load(strFileLocation); 

XmlNodeList xmlNode = xmlDoc.GetElementsByTagName("UserSettings"); 

iの要素「ソース」(XML上記のm yの例?:「ソース」の要素に一致するように設定/サブスクリプションを渡すことによって読み)に基づく直接読むにはどうすればよい私はその本当の基本を知っているが、本当に混乱して!

+0

あなたの質問を言い換えてください。 – adatapost

+0

こんにちはAVD、これ以上の情報は必要ですか? – KeenUser

答えて

0

代わりに、SelectSingleNodeと組み合わせて、XPathという表現を使用すると、XmlDocumentを使用します。以下は、テストされていません:

XmlDocument doc = new XmlDocument(); 
strFileName = [...] 
doc.Load(strFileName); 
sourcetext=doc.SelectSingleNode("/UserSettings/Source").InnerText; 

編集:

ここでは、ソースに基づいてDestinationControllerを取得する方法について大まかな例です。

XmlDocument doc = new XmlDocument(); 
strFileName = [...] 
doc.Load(strFileName); 
dctext=doc.SelectSingleNode("/UserSettings/[Source=\"Your desired source\"]/DestinationController").InnerText; 
+0

ありがとうございます、ソーステキストには何が入っていますか?それに基づいて、私は対応するDstinationControllerとアクションを読む必要があります。どのようにすればいいですか? – KeenUser

+0

'sourcetext'は' 'タグとその子のテキストを含みます。 –

+0

OK要素(ソース)に基づいてノードタグ(Usersetting)を取得することは可能ですか? – KeenUser

1

(インポートSystem.Xml.Linq名前空間)を使用してください。

XDocument doc = XDocument.Load(filename); 
string value = doc.Root.Element("Source").Value; 
関連する問題