C# 合并时XPath表达式不起作用

C# 合并时XPath表达式不起作用,c#,csv,xpath,expression,C#,Csv,Xpath,Expression,在xpath表达式中组合时遇到问题: 以下是我的xml: <m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"> <d:Guid>fizeofnpj-dzeifjzenf-ezfizef</d:Guid> <d

在xpath表达式中组合时遇到问题:

以下是我的xml:

<m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<d:Guid>fizeofnpj-dzeifjzenf-ezfizef</d:Guid>
<d:ObjectId>6000009251</d:ObjectId>
<d:ProcessType>ZMIN</d:ProcessType>
<d:ProcessTypeTxt>Incident</d:ProcessTypeTxt>
<d:Description>Test 2</d:Description>
<d:IntroText>Incident (IT Service Management)</d:IntroText>
<d:CreatedAtDateFormatted>08.05.18</d:CreatedAtDateFormatted>
<d:ChangedAtDateFormatted>08.05.18</d:ChangedAtDateFormatted>
<d:PostingDate>2018-05-08T00:00:00</d:PostingDate>
<d:ChangedAtDate>2018-05-08T00:00:00</d:ChangedAtDate>
<d:Priority>2</d:Priority>
<d:PriorityTxt>2: High</d:PriorityTxt>
<d:PriorityState>None</d:PriorityState>
<d:Concatstatuser>New</d:Concatstatuser>
<d:ActionRequired>false</d:ActionRequired>
<d:StillOpen>true</d:StillOpen>
<d:Icon />
<d:SoldToPartyName />
<d:ServiceTeamName />
<d:PersonRespName />
<d:CategoryTxt>Change - Interface - Evolutive Maintenance</d:CategoryTxt>
<d:ConfigItemTxt />
<d:SAPComponent>BC-BCS-VAS</d:SAPComponent>
但是当我使用combine时,它不会返回所需的值,尽管我使用了一个在线工具来验证我的xPath表达式

下面是我使用combine时的表达式:

//content/m:properties/d:Guid | //content/m:properties/d:ObjectId

谁能告诉我为什么会这样?要正确使用我的表达式需要做些什么?

在我看来,Cinchoo没有实现对这种语法的任何支持

但是,仅使用直接LINQ to XML实现您想要的是非常简单的:

var doc=XDocument.Load(启动路径);
xd=”http://schemas.microsoft.com/ado/2007/08/dataservices"
var elements=doc.subjects()
其中(e=>e.Name==d+“Guid”| | e.Name==d+“ObjectId”);
foreach(元素中的var元素)
{
//写入文件
}

以下是如何使用Cinchoo ETL选择选定节点并将其写入CSV文件

var nsManager = new XmlNamespaceManager(new NameTable());
//register mapping of prefix to namespace uri 
nsManager.AddNamespace("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
nsManager.AddNamespace("d", "http://schemas.microsoft.com/ado/2007/08/dataservices");

StringBuilder csv = new StringBuilder();
using (var p = ChoXmlReader.LoadText(xml)
        .WithXPath("//entry/content/m:properties")
        .WithXmlNamespaceManager(nsManager)
        .WithField("Guid", xPath: "d:Guid")
        .WithField("ProcessType", xPath: "d:ProcessType")
        .WithField("Description", xPath: "d:Description")
    )
{
    using (var w = new ChoCSVWriter(csv)
        .WithFirstLineHeader()
        )
        w.Write(p);
}

Console.WriteLine(csv);

/m:properties/d:Guid |/m:properties/d:objective我非常震惊;声称这是XPath是严重的误传。就我所见,他们的API文档并没有暗示他们的“XPath”只是一小部分。非常感谢!但是你没有得到文本tho。要检索文本,您应该使用(var p=ChoXmlReader.LoadText(xmlDocument).WithXPath(Utils.GetXpath()).WithField(“Guid”,xpath:“d:Guid/text()”).WithField(“ProcessType”,xpath:“d:ProcessType/text()”).WithField(“Description”,xpath:“d:Description/text()”))
var nsManager = new XmlNamespaceManager(new NameTable());
//register mapping of prefix to namespace uri 
nsManager.AddNamespace("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
nsManager.AddNamespace("d", "http://schemas.microsoft.com/ado/2007/08/dataservices");

StringBuilder csv = new StringBuilder();
using (var p = ChoXmlReader.LoadText(xml)
        .WithXPath("//entry/content/m:properties")
        .WithXmlNamespaceManager(nsManager)
        .WithField("Guid", xPath: "d:Guid")
        .WithField("ProcessType", xPath: "d:ProcessType")
        .WithField("Description", xPath: "d:Description")
    )
{
    using (var w = new ChoCSVWriter(csv)
        .WithFirstLineHeader()
        )
        w.Write(p);
}

Console.WriteLine(csv);