小编cla*_*cke的帖子

如何从shell执行XPath单行程序?

对于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 …

xml shell xpath cross-platform

182
推荐指数
7
解决办法
12万
查看次数

最简单的反向代理

我正在寻找一种简单地在本地设置连接到远程站点的代理的方法.我不想在系统中安装任何东西.如果我可以通过单个命令行调用来调用它,而不是使用单个配置文件,那就太棒了.

目的是嗅探我正在开发的本地应用程序与其他人提供并使用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/ ProxyPassReverseconfig 的Apache ,但它感觉有点过分,需要使用配置文件.

更新:另一个不适用的解决方案是实际的HTTP代理,而不是模拟远程站点的代理.因为远程站点是一个HTTPS站点,这只会使我的应用程序在代理中执行CONNECT并且没有获得任何内容.

ruby python reverse-proxy node.js

22
推荐指数
1
解决办法
2万
查看次数

Ant macrodef:有没有办法获取元素参数的内容?

我正在尝试在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)

ant element macrodef

8
推荐指数
1
解决办法
5671
查看次数

Python + Expat:错误&#0; 实体

我编写了一个小函数,它使用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>&#0;</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)

python xml parsing elementtree expat-parser

5
推荐指数
1
解决办法
4059
查看次数