Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何用C解析xpath if语句#_C#_Xml_Xpath - Fatal编程技术网

C# 如何用C解析xpath if语句#

C# 如何用C解析xpath if语句#,c#,xml,xpath,C#,Xml,Xpath,我有一个包含if语句的xpath。我想用c#来评估它。如果在xpath中没有任何函数,则使用 node.SelectSingleNode(xpath); 当我尝试使用if语句执行此操作时,我得到一个无效的令牌错误 这是我的xpath: if (substring-before(substring-after(//IzdaniRacunEnostavni/@xsi:noNamespaceSchemaLocation,'http://www.gzs.si/e-poslovanje/sheme/')

我有一个包含if语句的xpath。我想用c#来评估它。如果在xpath中没有任何函数,则使用

node.SelectSingleNode(xpath);
当我尝试使用if语句执行此操作时,我得到一个无效的令牌错误

这是我的xpath:

if (substring-before(substring-after(//IzdaniRacunEnostavni/@xsi:noNamespaceSchemaLocation,'http://www.gzs.si/e-poslovanje/sheme/'),'_EnostavniRacun.xsd')='eSLOG_1-6') then //Postavka/StevilkaVrstice[text()!='']/../../ZneskiPostavke/VrstaZneskaPostavke[text() ='203']/../ZnesekPostavke else     //Postavka/StevilkaVrstice[text() !='']/../../ZneskiPostavke/VrstaZneskaPostavke[text() ='66']/../ZnesekPostavke

如果我用它测试这个xpath,它将显示为有效的。

将xpath的
If-else
部分翻译成C#语句可能是使用C#和xpath 1.0的最佳选择。xpath
if-else
块的格式化版本如下所示:

if (substring-before(substring-after(//IzdaniRacunEnostavni/@xsi:noNamespaceSchemaLocation,'http://www.gzs.si/e-poslovanje/sheme/'),'_EnostavniRacun.xsd')='eSLOG_1-6') 

then 

//Postavka/StevilkaVrstice[text()!='']/../../ZneskiPostavke/VrstaZneskaPostavke[text() ='203']/../ZnesekPostavke 

else    

//Postavka/StevilkaVrstice[text() !='']/../../ZneskiPostavke/VrstaZneskaPostavke[text() ='66']/../ZnesekPostavke
尝试将它们转换为此C#
if else
块:

var xpathIfResult = node.SelectSingleNode("//IzdaniRacunEnostavni[substring-before(substring-after(@xsi:noNamespaceSchemaLocation,'http://www.gzs.si/e-poslovanje/sheme/'),'_EnostavniRacun.xsd')='eSLOG_1-6']");
if(xpathIfResult != null)
{
    result = node.SelectSingleNode("//Postavka/StevilkaVrstice[text() !='']/../../ZneskiPostavke/VrstaZneskaPostavke[text() ='66']/../ZnesekPostavke");
}
else
{
    result = node.SelectSingleNode("//Postavka/StevilkaVrstice[text() !='']/../../ZneskiPostavke/VrstaZneskaPostavke[text() ='66']/../ZnesekPostavke");
}

你在找什么?请注意,您添加的验证器是针对XPath 2.0的,它不是.Net Framework的Xml类的一部分。嗯,我相信.Net 4.5支持XPath 2.0…它不应该是“eq”而不是IF中的等号(=)吗expression@Vizard不,它也不起作用.“4.5支持的XPath 2.0”的链接是什么?我的想法是:“微软……为……XML路径语言(XPath)1.0提供开发人员支持”,这会起作用,但在我的情况下不会。。。我找到了xpath2.codeplex.com,它可以正常工作。。