<?xml version="1.0" encoding="ISO-8859-1" ?>
- <OrderFeed>
- <Order id="1">
- <BillingInformation>
<Name>Bruce Ganek</Name>
<Address>99 Main Street</Address>
<City>Cranston</City>
<State>RI</State>
<ZipCode>02910</ZipCode>
</BillingInformation>
- <ShippingInformation>
<Name>Governor Chafee</Name>
<Address>82 Smith St # 115</Address>
<City>Providence</City>
<State>RI</State>
<ZipCode>02903-1121</ZipCode>
</ShippingInformation>
- <Items>
- <Item>
<PartNo>JETSWEATER</PartNo>
<Description>N.Y. Jets Sweatshirt</Description>
<UnitPrice>10.50</UnitPrice>
<Quantity>2</Quantity>
<TotalCost>21.00</TotalCost>
- <CustomerOptions>
<Size>M</Size>
<Color>Green</Color>
</CustomerOptions>
</Item>
- <Item>
<PartNo>JETSWEATER</PartNo>
<Description>N.Y. Jets Sweatshirt</Description>
<UnitPrice>7.50</UnitPrice>
<Quantity>3</Quantity>
<TotalCost>22.50</TotalCost>
- <CustomerOptions>
<Size>S</Size>
<Color>White</Color>
</CustomerOptions>
</Item>
- <Item>
<PartNo>JETSFLASHLIGHT</PartNo>
<Description>N.Y. Jets Flashlight</Description>
<UnitPrice>5.00</UnitPrice>
<Quantity>1</Quantity>
<TotalCost>5.00</TotalCost>
<CustomerOptions />
</Item>
</Items>
</Order>
- <Order id="2">
- <BillingInformation>
<Name>Walt Disney</Name>
<Address>DisneyWorld Hotel</Address>
<City>Orlando</City>
<State>FL</State>
<ZipCode>32801</ZipCode>
</BillingInformation>
- <ShippingInformation>
<Name>Walt Disney</Name>
<Address>DisneyWorld Hotel</Address>
<City>Orlando</City>
<State>FL</State>
<ZipCode>32801</ZipCode>
</ShippingInformation>
- <Items>
- <Item>
<PartNo>JETSWEATER</PartNo>
<Description>N.Y. Jets Sweatshirt</Description>
<UnitPrice>10.50</UnitPrice>
<Quantity>2</Quantity>
<TotalCost>21.00</TotalCost>
- <CustomerOptions>
<Size>M</Size>
<Color>Green</Color>
</CustomerOptions>
</Item>
- <Item>
<PartNo>JETSWEATER</PartNo>
<Description>N.Y. Jets Sweatshirt</Description>
<UnitPrice>7.50</UnitPrice>
<Quantity>3</Quantity>
<TotalCost>22.50</TotalCost>
- <CustomerOptions>
<Size>S</Size>
<Color>White</Color>
</CustomerOptions>
</Item>
- <Item>
<PartNo>JETSFLAG</PartNo>
<Description>N.Y. Jets Flag for display</Description>
<UnitPrice>5.00</UnitPrice>
<Quantity>1</Quantity>
<TotalCost>5.00</TotalCost>
<CustomerOptions />
</Item>
</Items>
</Order>
- <Order id="3">
- <BillingInformation>
<Name>Tom Brady</Name>
<Address>One Patriot Place</Address>
<City>Foxboro</City>
<State>MA</State>
<ZipCode>02035</ZipCode>
</BillingInformation>
- <ShippingInformation>
<Name>Tom Brady</Name>
<Address>2121 George Halas Drive</Address>
<City>Canton</City>
<State>OH</State>
<ZipCode>44708</ZipCode>
</ShippingInformation>
- <Items>
- <Item>
<PartNo>JETPANTS</PartNo>
<Description>N.Y. Jets Sweatpants</Description>
<UnitPrice>10.50</UnitPrice>
<Quantity>3</Quantity>
<TotalCost>31.50</TotalCost>
- <CustomerOptions>
<Size>M</Size>
<Color>Green</Color>
</CustomerOptions>
</Item>
- <Item>
<PartNo>JETSWEATER</PartNo>
<Description>N.Y. Jets Sweatshirt</Description>
<UnitPrice>7.50</UnitPrice>
<Quantity>1</Quantity>
<TotalCost>7.50</TotalCost>
- <CustomerOptions>
<Size>S</Size>
<Color>White</Color>
</CustomerOptions>
</Item>
- <Item>
<PartNo>JETSFLAG</PartNo>
<Description>N.Y. Jets Flag for display</Description>
<UnitPrice>5.00</UnitPrice>
<Quantity>1</Quantity>
<TotalCost>5.00</TotalCost>
<CustomerOptions />
</Item>
</Items>
</Order>
</OrderFeed>
上面是我正在解析的xml文档。我的目标是使用输入 PartNo,例如“JETSFLAG”是他们传递给应用程序的字符串。我想在 OrderFeed 中查找所有订单,并计算 PartNo 具体被购买的次数。我有一个 XPath Navigator 工具,由于某种原因,当我编写应该工作以获取我想要的内容的表达式时,它不会返回任何内容。
这是我在评估表达式时得到的结果://OrderFeed/Order/Items//Item//PartNo 这让我得到了我需要的数据,我只需要用户输入的任何特定项目的计数...
<xml>JETSWEATER JETSWEATER JETSFLASHLIGHT JETSWEATER JETSWEATER JETSFLAG JETPANTS JETSWEATER JETSFLAG</xml>
现在,我很确定编写 count(//OrderFeed/Order/Items//Item//PartNo[JETSFLAG]) 应该会计算 2 个项目。但这就是我得到的返回......
<xml>0</xml>
当它显示时,我得到返回 0 的计数。有人可以帮忙吗?
最佳答案
尝试路径:
/OrderFeed/Order/Items/Item[PartNo=JETSFLAG]
(根据您的环境引用)
关于c# - 无法计算出 XPath 计数表达式结果。 C# xml Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29710046/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
我正在尝试使用ruby和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
在我的应用程序中,我需要能够找到所有数字子字符串,然后扫描每个子字符串,找到第一个匹配范围(例如5到15之间)的子字符串,并将该实例替换为另一个字符串“X”。我的测试字符串s="1foo100bar10gee1"我的初始模式是1个或多个数字的任何字符串,例如,re=Regexp.new(/\d+/)matches=s.scan(re)给出["1","100","10","1"]如果我想用“X”替换第N个匹配项,并且只替换第N个匹配项,我该怎么做?例如,如果我想替换第三个匹配项“10”(匹配项[2]),我不能只说s[matches[2]]="X"因为它做了两次替换“1fooX0barXg
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
最近,当我启动我的Rails服务器时,我收到了一长串警告。虽然它不影响我的应用程序,但我想知道如何解决这些警告。我的估计是imagemagick以某种方式被调用了两次?当我在警告前后检查我的git日志时。我想知道如何解决这个问题。-bcrypt-ruby(3.1.2)-better_errors(1.0.1)+bcrypt(3.1.7)+bcrypt-ruby(3.1.5)-bcrypt(>=3.1.3)+better_errors(1.1.0)bcrypt和imagemagick有关系吗?/Users/rbchris/.rbenv/versions/2.0.0-p247/lib/ru