how to disable dtd at runtime in java’s xpath?

You should be able to specify your own EntityResolver, or use specific features of your parser? See here for some approaches. A more complete example: <?xml version=”1.0″?> <!DOCTYPE foo PUBLIC “//FOO//” “foo.dtd”> <foo> <bar>Value</bar> </foo> And xpath usage: import java.io.File; import java.io.IOException; import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; import … Read more

XSLT – Comparing preceding-sibling’s elements with current’s node element

Almost correct. <xsl:if test=”preceding-sibling::recurso[1]/unidad != unidad”> </xsl:if> The :: is for axes, not for moving along a path (“making a location step”). In XPath terminology: preceding-sibling::recurso[1]/unidad != unidad ””””””””’ ++++++++++ ++++++ ### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ ‘ = axis name (optional, defaults to “child”) + = node test (required) # = predicate (optional, for filtering) ~ = … Read more

XPath axis, get all following nodes until

Use: (//h2[. = ‘Foo bar’])[1]/following-sibling::p [1 = count(preceding-sibling::h2[1] | (//h2[. = ‘Foo bar’])[1])] In case it is guaranteed that every h2 has a distinct value, this may be simplified to: //h2[. = ‘Foo bar’]/following-sibling::p [1 = count(preceding-sibling::h2[1] | ../h2[. = ‘Foo bar’])] This means: Select all p elements that are following siblings of the h2 … Read more

XPathSelectElement always returns null

When namespaces are used, these must be used in the XPath query also. Your XPath query would only work against elements with no namespace (as can be verified by removing the namespace from your XML). Here’s an example showing how you create and pass a namespace manager: var xml = … XML from your post … Read more

How to click on the radio button through the element ID attribute using Selenium and C#

To locate the element you can use either of the following Locator Strategies: CssSelector: driver.FindElement(By.CssSelector(“input#group[value=”In_Group”]”)); XPath: driver.FindElement(By.XPath(“//input[@id=’group’ and @value=”In_Group”]”)); However, as it is a <input> element and possibly you will interact with it ideally you have to induce WebDriverWait for the desired ElementToBeClickable() and you can use either of the following Locator Strategies: CssSelector: new … Read more

How to extract the dynamic values of the id attributes of the table elements using Selenium and Java

Until you find the element first, you can’t retrieve the attribute values of it. Use findElements method to fetch all links using the following locator table tr td[class=”journalTable-journalPost”] a Then iterate through each element using for-each to fetch id for each element. Sample code: List<WebElement> listOfLinks = driver.findElements(By.cssSelector(“table tr td[class=”journalTable-journalPost”] a”)); for(WebElement link: listOfLinks) { … Read more

How to click on Load More button within Google Trends and print all the titles through Selenium and Python

To click on LOAD MORE button to load more real-time searches and then to print them you can use the following solution: Code Block: # -*- coding: UTF-8 -*- from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import TimeoutException options = webdriver.ChromeOptions() options.add_argument(“start-maximized”) … Read more

Java How to extract a complete XML block

Adding to lwburk’s solution, to convert a DOM Node to string form, you can use a Transformer: private static String nodeToString(Node node) throws TransformerException { StringWriter buf = new StringWriter(); Transformer xform = TransformerFactory.newInstance().newTransformer(); xform.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, “yes”); xform.transform(new DOMSource(node), new StreamResult(buf)); return(buf.toString()); } Complete example: public static void main(String… args) throws Exception { String xml = … Read more

Library to query HTML with XPath in Java?

There are several different approaches to this documented on the Web: Using HtmlCleaner HtmlCleaner / Java DOM parser – Using XPath Contains against HTML in Java (This is the way I recommend) HtmlCleaner itself has a built in utility supporting XPath – See the javadocs http://htmlcleaner.sourceforge.net/doc/org/htmlcleaner/XPather.html or this example http://thinkandroid.wordpress.com/2010/01/05/using-xpath-and-html-cleaner-to-parse-html-xml/ Using Jericho Jericho and Jaxen … Read more