对于Ubuntu和/或CentOS,是否有一个包,它有一个命令行工具,可以执行XPath单线程,foo //element@attribute filename.xml
或者foo //element@attribute < filename.xml
逐行返回结果?
我正在寻找一些可以让我只是apt-get install foo
或者yum install foo
然后只是开箱即用,没有包装或其他必要的改编的东西.
以下是一些接近的事例:
引入nokogiri.如果我写这个包装器,我可以用上面描述的方式调用包装器:
#!/usr/bin/ruby
require 'nokogiri'
Nokogiri::XML(STDIN).xpath(ARGV[0]).each do |row|
puts row
end
Run Code Online (Sandbox Code Playgroud)
XML :: XPath的.可以使用这个包装器:
#!/usr/bin/perl
use strict;
use warnings;
use XML::XPath;
my $root = XML::XPath->new(ioref => 'STDIN');
for my $node ($root->find($ARGV[0])->get_nodelist) {
print($node->getData, "\n");
}
Run Code Online (Sandbox Code Playgroud)
xpath
来自XML :: XPath返回太多噪音,-- NODE --
和attribute = "value"
.
xml_grep
来自XML :: Twig无法处理不返回元素的表达式,因此无法在不进一步处理的情况下提取属性值.
编辑:
echo cat //element/@attribute | xmllint --shell filename.xml
返回类似的噪音xpath …
我正在寻找一种简单地在本地设置连接到远程站点的代理的方法.我不想在系统中安装任何东西.如果我可以通过单个命令行调用来调用它,而不是使用单个配置文件,那就太棒了.
目的是嗅探我正在开发的本地应用程序与其他人提供并使用HTTPS的远程服务器之间的流量.
最好是Ruby,Python或Node包,这样我就可以按照以下方式做一些事情:
mkdir simplest-proxy; cd simplest-proxy; bundle init
echo "gem 'simplest-proxy'" >> Gemfile; bundle --path vendor/bundle
bundle exec bin/simplest-proxy -p 8080 https://remote.site.example.com/
Run Code Online (Sandbox Code Playgroud)
要么
virtualenv simplest-proxy; cd simplest-proxy
bin/easy_install simplest-proxy
bin/simplest-proxy -p 8080 https://remote.site.example.com/
Run Code Online (Sandbox Code Playgroud)
要么
mkdir simplest-proxy; cd simplest-proxy
npm install simplest-proxy
node_modules/.bin/simplest-proxy -p 8080 https://remote.site.example.com/
Run Code Online (Sandbox Code Playgroud)
它将允许我的应用程序连接到localhost:8080
,它将转发请求(并重写Host
标题和其他任何必要的)到远程站点.我可以lo
在WireShark中观看并了解发生了什么.
我已经快速浏览了pypi,rubygems和npm,但是到目前为止我发现的要么是不工作(proxylet
否则看起来很有希望),用于更复杂的场景并需要设置(dj-revproxy
)或期望是用正确的Host
(node-reverse-proxy
)调用而不是重写.
更新:我现在正在使用带有ProxyPass
/ ProxyPassReverse
config 的Apache ,但它感觉有点过分,需要使用配置文件.
更新:另一个不适用的解决方案是实际的HTTP代理,而不是模拟远程站点的代理.因为远程站点是一个HTTPS站点,这只会使我的应用程序在代理中执行CONNECT并且没有获得任何内容.
我正在尝试在Ant中调试macrodef.我似乎无法找到一种方法来显示作为元素发送的参数的内容.
<project name='debug.macrodef'>
<macrodef name='def.to.debug'>
<attribute name='attr' />
<element name='elem' />
<sequential>
<echo>Sure, the attribute is easy to debug: @{attr}</echo>
<echo>The element works only in restricted cases: <elem /> </echo>
<!-- This works only if <elem /> doesn't contain anything but a
textnode, if there were any elements in there echo would
complain it doesn't understand them. -->
</sequential>
</macrodef>
<target name='works'>
<def.to.debug attr='contents of attribute'>
<elem>contents of elem</elem>
</def.to.debug>
</target>
<target name='does.not.work'>
<def.to.debug attr='contents of attribute'>
<elem><sub.elem>contents of sub.elem</sub.elem></elem> …
Run Code Online (Sandbox Code Playgroud) 我编写了一个小函数,它使用ElementTree和xpath来提取xml文件中某些元素的文本内容:
#!/usr/bin/env python2.5
import doctest
from xml.etree import ElementTree
from StringIO import StringIO
def parse_xml_etree(sin, xpath):
"""
Takes as input a stream containing XML and an XPath expression.
Applies the XPath expression to the XML and returns a generator
yielding the text contents of each element returned.
>>> parse_xml_etree(
... StringIO('<test><elem1>one</elem1><elem2>two</elem2></test>'),
... '//elem1').next()
'one'
>>> parse_xml_etree(
... StringIO('<test><elem1>one</elem1><elem2>two</elem2></test>'),
... '//elem2').next()
'two'
>>> parse_xml_etree(
... StringIO('<test><null>�</null><elem3>three</elem3></test>'),
... '//elem2').next()
'three'
"""
tree = ElementTree.parse(sin)
for element in tree.findall(xpath):
yield element.text
if __name__ …
Run Code Online (Sandbox Code Playgroud)