スキップしてメイン コンテンツに移動

投稿

ラベル(XPath)が付いた投稿を表示しています

Treat XPath Only Using Library Provided by Java SDK

Have you ever treated XML only using library provided in Java SDK? I think many people use external library for treating XML in Java. To be honest, I would prefer to use JDom ;P But I think it's good thing to know how to treat XML only using Java SDK. I will show you small code snippet for treating XML especially from XPath usage. The classes you should remember for treating XML is: DocumentBuilderFactory DocumentBuilder Document XPathFactory XPath XPathExpression XPathConstants NodeList Node Oops, a bit quite too much. Anyway I will show you an example code for reading XML string and select nodes by XPath. package com.dulesoftware.xpath; import java.io.IOException; import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax...

The Easiest Way To Getting XPath of Html Element

Some of you feel a bit annoying for writing XPath to specify html element in Selenium Test. I think the easiest way is using Chrome or using Firebug of Firefox. Chrome Right click html area you would like to get XPath, and select "Inspect element" Right click the html element and select "Copy XPath" in the opened area Firebug Right click html area you would like to get XPath, and select "Inspect Element with Firebug" Right click the html element and select "Copy XPath" in the opened area

C#: XPath and HtmlTextWriter Example

Hey guys!! This post show you how to use XPath in C#. I wrote program for formatting rss feed (xml) to html for its example. XPath in C# The simplest way is just creating XmlDocument and call SelectNodes method. var xmlString = "some xml string...." // create XmlDocment var doc = new XmlDocument(); doc.LoadXml(xmlString); // selecting nodes by xpath string doc.SelectNodes("/rss/channel/item"); RSS Xml to Html Example Okay here is a simple XPath example - converting rss xml to html. using System.IO; using System.Web.UI; using System.Web; namespace Utility { public class RSStoHtmlWriter : HTMLWriteHelper { private readonly string url; public RSStoHtmlWriter(string url) { this.url = url; } public override void WriteBody(HtmlTextWriter htmlWriter) { using (var reader = new XmlTextReader(url)) { // **** using XPath!! **** // As you n...