Java Reference
In-Depth Information
xml.append("<book isbn=\""+book.getisbn()+"\" "+
"pubyear=\""+book.getpubyear()+"\">");
xml.append("<title>"+book.getTitle()+"</title>");
for (Author author: book.getAuthors())
xml.append("<author>"+author.getName()+"</author>");
xml.append("<publisher>"+book.getPublisher()+"</publisher>");
xml.append("</book>");
return
new
StreamSource(new
StringRead-
er(xml.toString()));
}
}
private Source doPost(MessageContext msgContext, Source
source)
{
try
{
DOMResult dom = new DOMResult();
Transformer
t
=
TransformerFact-
ory.newInstance().newTransformer();
t.transform(source, dom);
XPathFactory xpf = XPathFactory.newInstance();
XPath xp = xpf.newXPath();
NodeList books = (NodeList) xp.evaluate("/book",
dom.getNode(),
XPathCon-
stants.NODESET);
String isbn = xp.evaluate("@isbn", books.item(0));
if (library.containsKey(isbn))
throw new HTTPException(400);
String
pubYear
=
xp.evaluate("@pubyear",
books.item(0));
String
title
=
xp.evaluate("title",
books.item(0)).trim();
String
publisher
=
xp.evaluate("publisher",
books.item(0)).trim();
NodeList
authors
=
(NodeList)
Search WWH ::




Custom Search