我已经检查了与我的问题相关的所有问题,但没有一个问题可以解决我的问题。我的问题是我需要使用XPath比较两个XML节点值。下面是XML
<ExtenProp>
<GenericField>
<FieldKey>IsDiscount</FieldKey>
<FieldValue>True</FieldValue>
<Namespace />
<ExtendedProperties />
</GenericField>
我需要检查IsDiscount是否可用,然后值为true。 我试着像这样检查
//do:OrderForms/do:OrderForm/do:ExtendedProperties/do:GenericField[FieldKey="IsDiscount" and FieldValue="True"]
并检查这是否等于true,但这不起作用。任何人都可以解释原因吗?
答案 0 :(得分:0)
您使用该XPath表达式正确。我怀疑问题只是缺少前缀 - 我想在FieldKey
和FieldValue
上映射到默认名称空间URI:
...../do:GenericField[do:FieldKey="IsDiscount" and do:FieldValue="True"]
答案 1 :(得分:0)
您必须从子元素中获取实际文本内容:
private void downloadByteStreamAsFile(Byte[] bytes, String fileName)
{
fileName = fileName.Replace(" ", "_");
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
if( fileName.Contains(".pdf")){
fileName = HttpUtility.UrlEncode(fileName);
//response.Flush(); //comment this or else no file returned
response.AddHeader("Content-Type", "application/pdf");
response.AddHeader("Content-Disposition",
"attachment; filename=" + fileName + "; size=" + bytes.Length.ToString());
response.BinaryWrite(bytes);
response.Flush();
response.End();
} else {
//response.Flush(); //comment this or else no file returned
response.AddHeader("Content-Type", "binary/octet-stream");
response.AddHeader("Content-Disposition",
"attachment; filename=" + fileName + "; size=" + bytes.Length.ToString());
response.BinaryWrite(bytes);
response.Flush();
response.End();
}
}
或
…/do:GenericField[do:FieldKey/text()="IsDiscount" and do:FieldValue/text()="True"]