【发布时间】:2019-07-29 09:36:20
【问题描述】:
在 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>
我正在尝试获取特定的标签名称值,例如
- d:Guid
- d:进程类型
- d:描述
我的问题是,在我的 c# 代码中这是有效的:
string xml = System.IO.File.ReadAllText(startupPath);
StringBuilder sb = new StringBuilder();
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");
using (var node = ChoXmlReader.LoadText(xml)
.WithXPath("//entry/content/m:properties/d:Guid")
.WithXmlNamespaceManager(nsManager)
)
{
using (var w = new ChoCSVWriter(sb).WithFirstLineHeader())
{
w.Write(node);
}
}
StreamWriter sw = new StreamWriter(resultsPath);
Console.WriteLine("csv" + sb.ToString());
sw.WriteLine(sb.ToString());
sw.Close();
但是当我使用 combine 时,它并没有返回我需要的值,尽管我使用了在线工具来验证我的 xPath 表达式。
这是我使用 combine 时的表达式:
//content/m:properties/d:Guid | //content/m:properties/d:ObjectId
谁能告诉我为什么会这样?以及需要做什么才能正确使用我的表达方式?
【问题讨论】:
-
/m:properties/d:Guid | /m:properties/d:ObjectId
标签: c# csv xpath expression