2016-09-17 10 views
0

私はXDocumentに解析されたXMLを持っている:私はそうエキスXdocument石鹸レスポンスボディ

<MyResponse xmlns="https://www.domain.net/"> 
     <Node1>0</Node1> 
    </MyResponse> 

としてそのルートを持つ新しいXDocumentを作成しようとしています。基本的

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <soap:Body> 
    <MyResponse xmlns="https://www.domain.net/"> 
     <Node1>0</Node1> 
    </MyResponse> 
    </soap:Body> 
</soap:Envelope> 

本質的に私は石鹸の体からこれを抽出しようとしています。私はLinqを使用してこれを解析しようとしましたが、この新しいルートで新しいXDocumentを返すように見えません。何か案は?私は、これはトリックを行うだろうと思い、事前

+0

'新しいXDocument(old.Element(「{} http://schemas.xmlsoap.org/soap/envelope/ Envelope ").Element(" {http://schemas.xmlsoap.org/soap/envelope/}Body ").Element(" {https://www.domain.net/}MyResponse "))' – PetSerAl

答えて

-1

ありがとう:

using System; 
using System.Xml.Linq; 

namespace SO39545160 
{ 
    class Program 
    { 
    static string xmlSource = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + 
     "<soap:Body>" + 
     "<MyResponse xmlns = \"https://www.domain.net/\" >" + 
     "<Node1 > 0 </Node1 >" + 
     "</MyResponse>" + 
     "</soap:Body>" + 
     "</soap:Envelope>"; 

    static void Main(string[] args) 
    { 
     XDocument xdoc = XDocument.Parse(xmlSource); 
     var subXml = xdoc.Document.Elements(XName.Get(@"{http://schemas.xmlsoap.org/soap/envelope/}Envelope")).Elements(XName.Get(@"{http://schemas.xmlsoap.org/soap/envelope/}Body")).Elements(XName.Get(@"{https://www.domain.net/}MyResponse")); 

     foreach (var node in subXml) 
     { 
     XDocument myRespDoc = new XDocument(node); 
     Console.WriteLine(myRespDoc); 
     } 
     Console.WriteLine(); 

     Console.WriteLine("END"); 
     Console.ReadLine(); 
    } 
    } 
} 
+0

はゼロを返します結果; – CR41G14

+0

@ CR41G14:これを実行すると、がコンソールにforeach-loopで出力されます。 xmlSource文字列をコピーしたときに破損している可能性がありますか? –

+0

これはvar newDoc = XDocument(response.Document.Descendants(XName.Get( "MyResponse"、 "https://www.domain.net/")));ガイダンスをありがとう! – CR41G14