- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
虽然我看到了类似的帖子,但我似乎无法解决这个问题(所以我是手动解析 xml 而不是使用 xpath 表达式)......这是我拥有的 XML......
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tnew="http://PR_Library/TNeWebService">
<soapenv:Header/>
<soapenv:Body>
<tnew:ApercuenRequest>
<tnew:OpcionCarga>0</tnew:OpcionCarga>
<tnew:Sucursal>1</tnew:Sucursal>
<tnew:Vendedor>8000</tnew:Vendedor>
<tnew:CanalConsulta>1</tnew:CanalConsulta>
<tnew:UsuarioCarga>8000</tnew:UsuarioCarga>
<tnew:Comercio>0</tnew:Comercio>
<tnew:FechaEvaluacion>20140109</tnew:FechaEvaluacion>
<tnew:ModeloDeEvaluacion></tnew:ModeloDeEvaluacion>
<tnew:IdEvaluacion>3694852</tnew:IdEvaluacion>
<tnew:Dudosa>0</tnew:Dudosa>
<tnew:Exceptuado>1</tnew:Exceptuado>
<tnew:TipoDocumento>1</tnew:TipoDocumento>
<tnew:NumeroDocumento>5881040</tnew:NumeroDocumento>
<tnew:Sexo>F</tnew:Sexo>
<tnew:Rol>5</tnew:Rol>
<tnew:RelacionLaboral>5</tnew:RelacionLaboral>
<tnew:TipoEmpleado>0</tnew:TipoEmpleado>
<tnew:FechaIngresoEmpleo></tnew:FechaIngresoEmpleo>
<tnew:AntiguedadLaboral>0</tnew:AntiguedadLaboral>
<tnew:IngresoMensualAnalista>0</tnew:IngresoMensualAnalista>
<tnew:IngresoMensual>6000</tnew:IngresoMensual>
<tnew:EstadoCivil>4</tnew:EstadoCivil>
<tnew:FechaDeNacimiento>19540423</tnew:FechaDeNacimiento>
<tnew:SituacionVivienda>3</tnew:SituacionVivienda>
<tnew:DomicilioProvincia></tnew:DomicilioProvincia>
<tnew:DomicilioLocalidad></tnew:DomicilioLocalidad>
<tnew:NivelEstudios></tnew:NivelEstudios>
<tnew:RelacionConTN>1</tnew:RelacionConTN>
<tnew:FechaAltaAbogado></tnew:FechaAltaAbogado>
<tnew:MarcaAbogado>N</tnew:MarcaAbogado>
<tnew:Cdi></tnew:Cdi>
<tnew:Campana></tnew:Campana>
</tnew:ApercuenRequest>
</soapenv:Body>
</soapenv:Envelope>
private XPathFactory xpathFactory = null;
private XPath xpath = null;
private DocumentBuilderFactory factory = null;
private DocumentBuilder builder= null;
private XPathExpression expr;
private Node nodo = null;
private Node nodoAux = null;
private NodeList result = null;
private NodeList nodeList = null;
...
try {
xpathFactory = XPathFactory.newInstance();
xpath = xpathFactory.newXPath();
factory = DocumentBuilderFactory.newInstance();
builder= factory.newDocumentBuilder();
NamespaceContext context = new NameSpaceNevada();
xpath.setNamespaceContext(context);
}
catch (Exception e) {
}
...
evaluarExpresion(documentoXML,"/soapenv:Envelope/soapenv:Body/tnew:ApercuenRequest/tnew:OpcionCarga")
private String evaluarExpresion(Document documentoXML, String expresion) throws Exception{
try {
expr = xpath.compile(expresion);
result = (NodeList)expr.evaluate(documentoXML, XPathConstants.NODESET);
System.out.println((result.item(0)!=null?result.item(0).getNodeName():"") + " ->>>> " + (result.item(0).getFirstChild()!=null?result.item(0).getFirstChild().getNodeValue():""));
return result.item(0).getFirstChild()!=null?result.item(0).getFirstChild().getNodeValue():null;
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
getNamespaceURI
方法来自
NameSpaceNevada
对象如下:
public String getNamespaceURI(String prefix) {
if (prefix == null) {
throw new IllegalArgumentException("No prefix provided!");
} else if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
return "http://univNaSpResolver/book";
} else if (prefix.equals("soapenv")) {
return "http://schemas.xmlsoap.org/soap/envelope/";
} else if (prefix.equals("tnew")) {
return "http://PR_Library/TNeWebService";
} else {
return XMLConstants.NULL_NS_URI;
}
}
最佳答案
与其将表达式作为节点集进行评估,然后再执行复杂的 DOM 操作来提取文本值,您还可以首先将表达式作为字符串进行评估。
expr.evaluate(documentoXML);
tnew:OpcionCarga
的文本内容。元素。
DocumentBuilderFactory
默认情况下是非命名空间感知的(在许多人看来这是一个非常糟糕的设计决策,但现在无法在不破坏向后兼容性的情况下进行纠正)-您必须这样做
factory.setNamespaceAware(true);
.newDocumentBuilder()
为了创建命名空间感知解析器。
关于xpath - Java Xpath 命名空间解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21186888/
编辑:为什么这被否决了?我真的不知道...顺便说一句 ../不起作用,因为我不想要 Table 的父级但实际上想要 ../td+1 我不知道这是否可能? 嗨,大家好。 我手头有一个相当复杂的问题..
我很难找到需要单击的输入(复选框)元素的 xpath。我正在尝试使用其他跨度元素来定位它。元素包含 Angular 属性,不知道这是否重要? 元素的结构如下: Company name
我正在尝试构建一个包含许多 XPath 作为参数的 DSL。我是 XPath 的新手,我需要一个 XPath 语法中从未使用过的字符,这样我就可以在脚本的一行中分隔 n 个 XPath。我的问题:哪些
使用xpath在父标签内找到特定标签: 输入样例:
我需要构造一个通用XPath来找到正确的节点,其中的标准是日期和时间。例如查找“ 5 May”,“ 12:17:44”的节点 XML具有日期和时间标签。 不方便地,日期标签仅在当天的第一次出现时填充。
我正在尝试获取xPath几个月内两个日期之间的差异。 几天之内我就没问题了(1127) days-from-duration(xs:date('2012-06-17')-xs:date('2009-0
我试图选择一个包含一段文本的元素,但是我不想选择包含该文本加上其他文本的元素。我通常会使用text()='abc def',但是这个特定元素在前后都包含空格。 这是一个示例片段:
亲爱的,您能帮我用这个XPATH吗?可以说我有以下HTML代码 text value1 value2 text 我需要构建一
我正在尝试提取带有排除项的 xpath,但无法执行此操作。 (//div[@class='row site country-names']/following-sibling::div)[1]/di
response.xpath('//*[@id="blah"]//text()') 假设我的html是 This is a simple text foo and this is after tag.
除了那些具有"//ul/li[not(@*)][count(*)=0]"父项的人以外,我需要全部接受。我已经尝试过,但是不幸的是它不起作用。 有谁知道,我该怎么处理? 提前致谢。 最佳答案 我认为您需
我使用XPath的问题是,每当我使用“子字符串”功能时,我只会得到一个匹配项,而我想全部获得它们。 另一个问题是,每当我使用“子字符串”和运算符的组合时它只是行不通(没有匹配项)。 例如:http:/
我正在尝试通过其位置和属性获取项目,但不知道如何做。 我要实现的是将这一点统一起来: Xpath("//h4/a[contains(@href,'#vuln_')]") 还有这个: Xpath
我有一个xpath如下: .//*[text()='Name:']/../child::select | .//*[text()='Name:']/../child::span 但是对我来说,它既不紧
我拼命试图在xpath中组合几个过滤器。假设我的数据如下所示: DELETE 1 This is my title my sh
我想在已经通过 xpath 设置的其他元素中使用 xpath 来指示元素的位置。 下面的一个已经通过 xpath 设置(我没有改变) //Base_Code
是否可以使用xpath直接在括号内抓取信息?还是以后再用正则表达式过滤? HTML如下所示: Product name (UN1QU3 C0D3) 使用以下Xpath表达式,我可以在此中获取所有内容:
我试图使用一个XPath表达式来选择一个节点,该节点的子节点与文档中的另一个节点匹配。 匹配将意味着该节点的所有属性都相同。因此,如果将一个节点与多个属性进行比较,则无法进行单独的属性比较。 作为示例
我想在 XPath 表达式中使用 Iverson 括号(即映射 true => 1,false => 0)。 示例:而不是书写 someNumber+(if(elem1/elem2[@attr='12
是否可以以类似方式选择节点? './tr[position() in (1, 3, 7)]' 我只找到以下解决方案: './tr[position() = 1 or position() = 3 or
我是一名优秀的程序员,十分优秀!