C# XDocument的XElement解析,远在下面,重复
我希望我的结果是这样的C# XDocument的XElement解析,远在下面,重复,c#,xml,parsing,C#,Xml,Parsing,我希望我的结果是这样的 // Boo1 // Boo2 // Boo3 // .... // .. // . 我是弗罗姆 //<xliff xmlns:sdl="http://sdl.com/FileTypes/SdlXliff/1.0" xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2" sdl: version="1.0"> // <sdl:seg-defs> // <
// Boo1
// Boo2
// Boo3
// ....
// ..
// .
我是弗罗姆
//<xliff xmlns:sdl="http://sdl.com/FileTypes/SdlXliff/1.0" xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2" sdl: version="1.0">
// <sdl:seg-defs>
// <sdl:seg id="1" conf="Translated">
// <sdl:prev-origin origin="source">
// <sdl:prev-origin origin="source">
// <sdl:prev-origin origin="tm" percent="99">
// <sdl:prev-origin/>
// <sdl:value key="Hash">Foo1</sdl:value>
// <sdl:value key="Created">Boo1</sdl:value>
//...
//..
//.
以下不是我想要的
// Foo1Boo1
// Foo2Boo2
// ....
// ..
// .
请帮忙
谢谢请尝试以下内容:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = @"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
List<XElement> segments = doc.Descendants().Where(x => x.Name.LocalName == "seg").ToList();
List<XElement> created = segments.Descendants().Where(x => (x.Name.LocalName == "value") && ((string)x.Attribute("key") == "Created")).ToList();
string results = string.Join("\n", created.Select(x => (string)x));
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Xml;
使用System.Xml.Linq;
命名空间控制台应用程序1
{
班级计划
{
常量字符串文件名=@“c:\temp\test.xml”;
静态void Main(字符串[]参数)
{
XDocument doc=XDocument.Load(文件名);
List segments=doc.subjects()。其中(x=>x.Name.LocalName==“seg”).ToList();
List created=segments.substands()。其中(x=>(x.Name.LocalName==“value”)&&((string)x.Attribute(“key”)==“created”)。ToList();
string results=string.Join(“\n”,created.Select(x=>(string)x));
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = @"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
List<XElement> segments = doc.Descendants().Where(x => x.Name.LocalName == "seg").ToList();
List<XElement> created = segments.Descendants().Where(x => (x.Name.LocalName == "value") && ((string)x.Attribute("key") == "Created")).ToList();
string results = string.Join("\n", created.Select(x => (string)x));
}
}
}