理解Java中的xml和url [英] understand xml and urls in Java
问题描述
我正在尝试使用此代码在.Net环境中重新创建类似的应用程序,但我对逻辑不太清楚。因此,我想寻求一些帮助,解释下面代码中发生了什么:
有一个contentCreator类,它会产生一个问题&我不太确定,它在这里做什么返回api.create(publication.findLink(issue),Utils.renderXml(document));
:
I am trying to use this code to recreate similar application in .Net environment, but I am little unclear of the logic. Hence I would like to seek some assistance, in explaining, what is going on in the code below:
There is a contentCreator class, which creates a issue & I am little unsure, what its doing here return api.create(publication.findLink("issue"), Utils.renderXml(document));
:
//ContentCreator
public static ApiObject createIssue(NotessaApi api, ApiObject publication, Issue issue) throws IOException {
Document document = Utils.createEmptyDocument();
Node node = Utils.createNode(document, "issue");
Utils.addXml(document, node, "title", issue.getTitle());
Utils.addXml(document, node, "approval_status", issue.getApprovalStatus());
Utils.addXml(document, node, "display_title", issue.getDisplayTitle());
Utils.addXml(document, node, "display_date", issue.getDisplayDate());
List<Property> properties = issue.getProperties();
if(!properties.isEmpty()) {
Node container = Utils.createNode(document, node, "properties");
for(Property property : properties) {
Element element = Utils.createNode(document, container, "property");
element.setAttribute("name", property.getName());
Utils.addXml(document, element, "value", property.getValue());
}
}
return api.create(publication.findLink("issue"), Utils.renderXml(document));
}
是否创建问题xml并将其转发到API Object类的findlink url。
API Object类创建以下两种方法:
Is it creating the issue xml and forwarding it to the findlink url from the API Object class.
API Object class creates the following two methods:
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
public URL findLink(String rel) {
String result = xpath("//link[contains(@rel,'" + rel + "')]/@href");
try {
return new URL(result);
} catch(MalformedURLException e) {
throw new RuntimeException(e);
}
}
public URL getSelfLink() throws MalformedURLException {
String uri = xpath("//@uri");
return new URL(uri);
}
任何进一步的建议,将非常感谢。非常感谢。
Any further advice, would be most appreciated. Many thanks.
推荐答案
return语句调出 api.create(publication.findLink(issue),Utils.renderXml (document));
并返回该方法返回的任何内容。
The return statement makes a call out to api.create(publication.findLink("issue"), Utils.renderXml(document));
and returns whatever is returned by that method.
这篇关于理解Java中的xml和url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!