Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Thursday, July 24, 2008

macrodef for xpathproperty in ant

No additional ant dependencies. as long as your in Java 6+

Usage:
<xpathproperty name="prop.name" value="//key/text()" file="my.xml" />

<macrodef name="xpathproperty">
<attribute name="name" />
<attribute name="value" />
<attribute name="file" />

<sequential>
<script language="javascript"> <![CDATA[
importPackage(javax.xml.xpath);
importPackage(java.io);
importClass(org.xml.sax.InputSource);

var xpathExp = XPathFactory.newInstance().newXPath().compile("@{value}");
var inputSource = new InputSource(new FileInputStream("@{file}"));

var prop = sfpricer.createTask("property");
prop.setName("@{name}");
prop.setValue(xpathExp.evaluate(inputSource));
prop.perform();

]]> </script>
</sequential>
</macrodef>

Tuesday, January 30, 2007

pretty schema

Schema should be self documenting, and what better way than using an xslt stylesheet to render it hyperlinked in html when opened in a browser?



Simply add the following prolog to your xml document right at the top of the schema:

<?xml-stylesheet type="text/xsl" href="xs3p.xsl"?>


and open it up in a browser. (You can also upload the schema to the site and see how it looks - try before you use)

Simple assertEquals in xml

While things like XmlUnit probably work well for complex xml differences, if you just need to compare two similar xml fragments then striping the whitespace from them and compare is easy in java (or any other language with regex).

Just do: myString.replaceAll("\\s*", "") on both the expected and actual result.