我想做这个:
//*福
返回名称以fu结尾的所有节点,例如<tarfu />和<snafu />,但不是<fubar />
XML文档:
<doc>
<A>
<Node>Hello!</Node>
</A>
<B>
<Node/>
</B>
<C>
</C>
<D/>
</doc>
Run Code Online (Sandbox Code Playgroud)
您将如何评估以下XPath查询?
/doc/A/Node != 'abcd'
/doc/B/Node != 'abcd'
/doc/C/Node != 'abcd'
/doc/D/Node != 'abcd'
Run Code Online (Sandbox Code Playgroud)
我希望所有这些都能评估为真.
但是,结果如下:
/doc/A/Node != 'abcd' true
/doc/B/Node != 'abcd' true
/doc/C/Node != 'abcd' false
/doc/D/Node != 'abcd' false
Run Code Online (Sandbox Code Playgroud)
这是预期的行为吗?或者它是我的XPath提供程序(jaxen)的错误?
我正在寻找正确的xpath语法来获取元素的特定父级.例:
root
|- div
| |
| |----??? ---|
| | |-a [class=1]
| | |- text[ A TEXT I DON'T WANT]
| |
| |
| |
| |-text[THE TEXT]
|
|-div
| |-text[THE TEXT I DON'T WANT]
|
|-div
| |-text[THE TEXT I DON'T WANT]
Run Code Online (Sandbox Code Playgroud)
我希望得到文本"THE TEXT",但是包含a [class=1]在同一个div中的文本.像这样的东西:
//div//a[@class=1]/text[contains(.,'A TEXT')]/parent::*/parent::*.... <till div element> /text
Run Code Online (Sandbox Code Playgroud) 我有一个XML文档,我需要删除特定的数据
xml文档的结构如下: -
<a>
<b select='yes please'>
<c d='text1' e='text11'/>
<c d='text2' e='text12'/>
<c d='text3' e='text13'/>
<c d='text4' e='text14'/>
<c d='text5' e='text15'/>
</b>
</a>
<a>
<b select='no thanks'>
<c d='text1' e='text21'/>
<c d='text3' e='text23'/>
<c d='text5' e='text25'/>
</b>
</a>
<a>
<b select='yes please'>
<c d='text1' e='text31'/>
<c d='text2' e='text32'/>
<c d='text3' e='text33'/>
<c d='text4' e='text34'/>
<c d='text5' e='text35'/>
</b>
</a>
<a>
<b select='no thanks'>
<c d='text4' e='text41'/>
<c d='text3' e='text43'/>
<c d='text5' e='text45'/>
</b>
</a>
Run Code Online (Sandbox Code Playgroud)
我只需要选择那些具有d attribute ='text1'和d attribute ='text4'的/ …
如何提取HTML标记值?
HTML:
<input type="hidden" name="text1" id="text1" value="need to get this">
Run Code Online (Sandbox Code Playgroud)
PHP:
$homepage = file_get_contents('http://www.example.com');
$doc = new DOMDocument;
$doc->preserveWhiteSpace = false;
@$doc->loadHTML($homepage);
$xpath = new DOMXpath($doc);
$filtered = $xpath->query("//input[@name='text1']");
Run Code Online (Sandbox Code Playgroud)
我怎样value才能"需要得到这个"?
更新:
我得到了它的工作,并希望它也会帮助其他人.在上面的代码之后,我得到了以下值:
echo $filtered->item(0)->getAttribute('value');
Run Code Online (Sandbox Code Playgroud) 我想获取name的值并使用XMLLint将其放入变量中
<body>
<value name="abc"></value>
</body>
echo 'cat //body/value/@name' | xmllint --shell "test.xml"
/ > -------
name="abc"
/ >
Run Code Online (Sandbox Code Playgroud)
所以我想将值"abc"赋给变量$ test
我想按类和文本查找xpath中的所有元素.我试过这个,但它不起作用.
// [contains(@class,'myclass')] // [text()='qwerty']
我试图找到所有具有'myclass'类和文本'qwert'的元素(这些将是span元素)
我有像这样的XML字符串
<resp><status>good</status><msg>hi</msg></resp>
Run Code Online (Sandbox Code Playgroud)
我听从了这个帮助
mycode的:
public static void main(String args[]) {
String xml = "<resp><status>good</status><msg>hi</msg></resp>";
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
InputSource source = new InputSource(new StringReader(xml));
String status = "";
String msg = "";
try {
status = (String) xpath.evaluate("/resp/status", source,XPathConstants.STRING);
msg = (String) xpath.evaluate("/resp/msg", source,XPathConstants.STRING);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("status=" + status);
System.out.println("Message=" + msg);
}
Run Code Online (Sandbox Code Playgroud)
我想得到msg节点值,但我得到了异常
java.io.IOException: Stream closed
at java.io.StringReader.ensureOpen(StringReader.java:39)
at java.io.StringReader.read(StringReader.java:73)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1742)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.arrangeCapacity(XMLEntityScanner.java:1619)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipString(XMLEntityScanner.java:1657)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:193)
at …Run Code Online (Sandbox Code Playgroud) 为什么不:
SELECT
SomeXmlColumn.nodes('/people/person') AS foo(b)
FROM MyTable
Run Code Online (Sandbox Code Playgroud)
工作?
几乎所有我在SQL Server中看到(或得到)使用XPath查询的答案要求您使用XML将XML文档加入自身CROSS APPLY.
为什么?
SELECT
p.value('(./firstName)[1]', 'VARCHAR(8000)') AS firstName,
p.value('(./lastName)[1]', 'VARCHAR(8000)') AS lastName
FROM table
CROSS APPLY field.nodes('/person') t(p)
Run Code Online (Sandbox Code Playgroud)
例如:
SELECT a.BatchXml.value('(Name)[1]', 'varchar(50)') AS Name,
a.BatchXml.value('(IDInfo/IDType)[1]', 'varchar(50)') AS IDType,
a.BatchXml.value('(IDInfo/IDOtherDescription)[1]', 'varchar(50)') AS IDOtherDescription
FROM BatchReports b
CROSS APPLY b.BatchFileXml.nodes('Customer') A(BatchXml)
WHERE a.BatchXml.exist('IDInfo/IDType[text()=3]')=1
Run Code Online (Sandbox Code Playgroud)
例如:
SELECT b.BatchID,
x.XmlCol.value('(ReportHeader/OrganizationReportReferenceIdentifier)[1]','VARCHAR(100)') AS OrganizationReportReferenceIdentifier,
x.XmlCol.value('(ReportHeader/OrganizationNumber)[1]','VARCHAR(100)') AS OrganizationNumber
FROM Batches b
CROSS APPLY b.RawXml.nodes('/CasinoDisbursementReportXmlFile/CasinoDisbursementReport') x(XmlCol);
Run Code Online (Sandbox Code Playgroud)
SELECT nref.value('first-name[1]', 'nvarchar(32)') FirstName,
nref.value('last-name[1]', 'nvarchar(32)') …Run Code Online (Sandbox Code Playgroud) 在Firefox 50.1中,Firebug不再可用,因此我必须使用检查器,但我找不到Firebug中提供的copy ---> xpath选项.如何使用检查器找到元素的xpath?