本文整理了Java中nu.xom.Element
类的一些代码示例,展示了Element
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element
类的具体详情如下:
包路径:nu.xom.Element
类名称:Element
暂无
代码示例来源:origin: stanfordnlp/CoreNLP
private static void addDependencyInfo(Element depInfo, String rel, boolean isExtra, int source, String sourceWord, Integer sourceCopy, int target, String targetWord, Integer targetCopy, String curNS) {
Element depElem = new Element("dep", curNS);
depElem.addAttribute(new Attribute("type", rel));
if (isExtra) {
depElem.addAttribute(new Attribute("extra", "true"));
}
Element govElem = new Element("governor", curNS);
govElem.addAttribute(new Attribute("idx", Integer.toString(source)));
govElem.appendChild(sourceWord);
if (sourceCopy != null && sourceCopy > 0) {
govElem.addAttribute(new Attribute("copy", Integer.toString(sourceCopy)));
}
depElem.appendChild(govElem);
Element dependElem = new Element("dependent", curNS);
dependElem.addAttribute(new Attribute("idx", Integer.toString(target)));
dependElem.appendChild(targetWord);
if (targetCopy != null && targetCopy > 0) {
dependElem.addAttribute(new Attribute("copy", Integer.toString(targetCopy)));
}
depElem.appendChild(dependElem);
depInfo.appendChild(depElem);
}
代码示例来源:origin: wiztools/rest-client
private void addFields(Elements eFields, ReqEntityBasePart part) {
if(eFields == null) {
return;
}
for(int i=0; i<eFields.size(); i++) {
Element eField = eFields.get(i);
String name = eField.getChildElements("name").get(0).getValue();
String value = eField.getChildElements("value").get(0).getValue();
part.addField(name, value);
}
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
public String getAttribute(int index) {
return currentElement.getAttribute(index).getValue();
}
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* Helper method for addWordInfo(). If the value is not null,
* creates an element of the given name and namespace and adds it to the
* tokenElement.
*
* @param tokenElement This is the element to which the newly created element will be added
* @param elemName This is the name for the new XML element
* @param curNS The current namespace
* @param value This is its value
*/
private static void setSingleElement(Element tokenElement, String elemName, String curNS, String value) {
if (value != null) {
Element cur = new Element(elemName, curNS);
cur.appendChild(value);
tokenElement.appendChild(cur);
}
}
代码示例来源:origin: wiztools/rest-client
private Element getRootElement() {
Element eRoot = new Element("rest-client");
// set version attributes to rest-client root tag
eRoot.addAttribute(new Attribute("version", Versions.CURRENT));
return eRoot;
}
代码示例来源:origin: org.concordion/concordion
public void beforeParsing(Document document) {
Element html = document.getRootElement();
Element head = html.getFirstChildElement("head");
Check.notNull(head, "<head> section is missing from document");
Element script = new Element("script");
script.addAttribute(new Attribute("type", "text/javascript") );
script.appendChild(javaScript);
head.insertChild(script, 0);
}
}
代码示例来源:origin: net.stickycode.plugins/bounds-maven-plugin
void updateProperty(Document pom, String propertyName, String newVersion) throws MojoExecutionException {
XPathContext context = new XPathContext("mvn", "http://maven.apache.org/POM/4.0.0");
Nodes nodes = pom.query("//mvn:properties", context);
if (nodes.size() > 0) {
final Element propertiesElement = (Element) nodes.get(0);
Elements properties = propertiesElement.getChildElements();
for (int i = 0; i < properties.size(); i++) {
Element property = properties.get(i);
if (property.getLocalName().equals(propertyName)) {
Element newRange = new Element(propertyName, "http://maven.apache.org/POM/4.0.0");
newRange.appendChild(newVersion);
propertiesElement.replaceChild(property, newRange);
}
}
}
}
代码示例来源:origin: wiztools/rest-client
if (!"rest-client".equals(rootNode.getQualifiedName())) {
throw new XMLException("Root node is not <rest-client>");
Versions.versionValidCheck(rootNode.getAttributeValue("version"));
if (rootNode.getChildElements().size() != 1) {
throw new XMLException("There can be only one child node for root node: <response>");
if (rootNode.getFirstChildElement("response") == null) {
throw new XMLException("The child node of <rest-client> should be <response>");
responseNode = rootNode.getFirstChildElement("response");
for (int i = 0; i < responseNode.getChildElements().size(); i++) {
tNode = responseNode.getChildElements().get(i);
String nodeName = tNode.getQualifiedName();
responseBean.setExecutionTime(Long.parseLong(tNode.getValue()));
} else if ("status".equals(nodeName)) {
responseBean.setStatusLine(tNode.getValue());
responseBean.setStatusCode(Integer.parseInt(tNode.getAttributeValue("code")));
} else if ("headers".equals(nodeName)) {
Map<String, String> m = getHeadersFromHeaderNode(tNode);
final String base64body = tNode.getValue();
responseBean.setResponseBody(Util.base64decodeByteArray(base64body));
} else if ("test-result".equals(nodeName)) {
TestResultBean testResultBean = new TestResultBean();
for (int j = 0; j < tNode.getChildCount(); j++) {
代码示例来源:origin: wiztools/xsd-gen
private void processAttributes(final Element inElement, final Element outElement) {
for (int i = 0; i < inElement.getAttributeCount(); i++) {
final Attribute attr = inElement.getAttribute(i);
final String name = attr.getLocalName();
final String value = attr.getValue();
Element attrElement = new Element(xsdPrefix + ":attribute", XSD_NS_URI);
attrElement.addAttribute(new Attribute("name", name));
attrElement.addAttribute(new Attribute("type", xsdPrefix + TypeInferenceUtil.getTypeOfContent(value)));
attrElement.addAttribute(new Attribute("use", "required"));
outElement.appendChild(attrElement);
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
Builder parser = new Builder();
StringReader in = new StringReader(xml);
docElem = parser.build(in).getRootElement();
} catch (ParsingException | IOException e) {
throw new RuntimeException(String.format("error:\n%s\ninput:\n%s", e, xml));
Element textElem = docElem.getFirstChildElement("TEXT");
StringBuilder text = new StringBuilder();
int offset = 0;
List<CoreMap> sentences = new ArrayList<>();
Elements sentenceElements = textElem.getChildElements("SENT");
for (int crtsent = 0; crtsent < sentenceElements.size(); crtsent ++){
Element sentElem = sentenceElements.get(crtsent);
CoreMap sentence = new ArrayCoreMap();
sentence.set(CoreAnnotations.CharacterOffsetBeginAnnotation.class, offset);
Tree tree = Tree.valueOf(sentElem.getChild(0).getValue()); // XXX ms: is this the same as sentElem.getText() in JDOM?
List<CoreLabel> tokens = new ArrayList<>();
List<Tree> preTerminals = preTerminals(tree);
String docID = docElem.getAttributeValue("id");
Matcher matcher = datePattern.matcher(docID);
matcher.find();
代码示例来源:origin: org.teiid/saxon-xom
/** Wraps each item in the result sequence into a decorated element wrapper. */
private static Document wrapSequence(Nodes nodes) {
// make a copy of the template for sequences:
Element items = (Element) TEMPLATES.get(Nodes.class.getName());
items = new Element(items);
int size = nodes.size();
for (int i=0; i < size; i++) {
items.appendChild(wrap(nodes.get(i)));
}
return new Document(items);
}
代码示例来源:origin: org.concordion/concordion
private boolean hasContentTypeMetadata(Element head) {
Elements metaChildren = head.getChildElements("meta");
for (int i=0; i < metaChildren.size(); i++) {
Element metaChild = metaChildren.get(i);
Attribute httpEquiv = metaChild.getAttribute("http-equiv");
if (httpEquiv != null && "content-type".equalsIgnoreCase(httpEquiv.getValue())) {
return true;
}
}
return false;
}
}
代码示例来源:origin: wiztools/rest-client
protected Request xml2Request(final Document doc)
throws MalformedURLException, XMLException {
// get the rootNode
Element rootNode = doc.getRootElement();
if (!"rest-client".equals(rootNode.getQualifiedName())) {
throw new XMLException("Root node is not <rest-client>");
}
// checking correct rest version
final String rcVersion = rootNode.getAttributeValue("version");
try {
Versions.versionValidCheck(rcVersion);
}
catch(Versions.VersionValidationException ex) {
throw new XMLException(ex);
}
readVersion = rcVersion;
// if more than two request element is present then throw the exception
if (rootNode.getChildElements().size() != 1) {
throw new XMLException("There can be only one child node for root node: <request>");
}
// minimum one request element is present in xml
if (rootNode.getFirstChildElement("request") == null) {
throw new XMLException("The child node of <rest-client> should be <request>");
}
Element requestNode = rootNode.getFirstChildElement("request");
return getRequestBean(requestNode);
}
代码示例来源:origin: wiztools/rest-client
private Map<String, String> getHeadersFromHeaderNode(final Element node)
throws XMLException {
Map<String, String> m = new LinkedHashMap<>();
for (int i = 0; i < node.getChildElements().size(); i++) {
Element headerElement = node.getChildElements().get(i);
if (!"header".equals(headerElement.getQualifiedName())) {
throw new XMLException("<headers> element should contain only <header> elements");
}
m.put(headerElement.getAttributeValue("key"),
headerElement.getAttributeValue("value"));
}
return m;
}
代码示例来源:origin: net.stickycode.plugins/bounds-maven-plugin
void bumpMajorVersion(Document pom) throws MojoExecutionException {
XPathContext context = new XPathContext("mvn", "http://maven.apache.org/POM/4.0.0");
Nodes project = pom.query("/mvn:project", context);
if (project.size() == 0)
throw new MojoExecutionException("Pom is broken");
Nodes nodes = pom.query("/mvn:project/mvn:version", context);
if (nodes.size() != 1)
throw new MojoExecutionException("Version is not declared correctly");
Element e = (Element) nodes.get(0);
String[] components = e.getValue().split("\\.");
components[0] = Integer.toString(Integer.valueOf(components[0]) + 1);
String bumpedVersion = String.join(".", components);
Element newVersion = new Element("version", "http://maven.apache.org/POM/4.0.0");
newVersion.appendChild(bumpedVersion);
((Element) project.get(0)).replaceChild(e, newVersion);
// TODO check that the next version does not already exist
}
代码示例来源:origin: se.vgregion.pubsubhubbub/pubsubhubbub-hub-composite-pubsub
public DefaultField(Element elm) {
this.name = elm.getLocalName();
this.namespace = elm.getNamespaceURI();
this.prefix = elm.getNamespacePrefix();
for(int i = 0; i<elm.getAttributeCount(); i++) {
Attribute attribute = elm.getAttribute(i);
fields.add(new DefaultField(attribute.getNamespaceURI(), attribute.getNamespacePrefix(), attribute.getLocalName(), attribute.getValue()));
}
this.content = XmlUtil.innerToString(elm);
}
代码示例来源:origin: nu.validator.htmlparser/htmlparser
@Override
protected void appendChildrenToNewParent(Element oldParent,
Element newParent) throws SAXException {
try {
Nodes children = oldParent.removeChildren();
for (int i = 0; i < children.size(); i++) {
newParent.appendChild(children.get(i));
}
} catch (XMLException e) {
fatal(e);
}
}
代码示例来源:origin: org.teiid/saxon-xom
private static void appendNodes(Element elem, Nodes nodes) {
if (nodes != null) {
int size = nodes.size();
for (int i=0; i < size; i++) {
Node node = nodes.get(i);
if (node instanceof Attribute) {
elem.addAttribute((Attribute) node);
} else {
elem.insertChild(node, elem.getChildCount());
}
}
}
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
public String getValue() {
// currentElement.getValue() not used as this includes text of child elements, which we don't want.
StringBuffer result = new StringBuffer();
int childCount = currentElement.getChildCount();
for(int i = 0; i < childCount; i++) {
Node child = currentElement.getChild(i);
if (child instanceof Text) {
Text text = (Text) child;
result.append(text.getValue());
}
}
return result.toString();
}
代码示例来源:origin: org.specrunner/specrunner-sql
@Override
public ISource transform(ISource source) throws SourceException {
Document d = source.getDocument();
Nodes tables = d.query("//table");
for (int i = 0; i < tables.size(); i++) {
Element table = (Element) tables.get(i);
table.addAttribute(new Attribute("class", getValue()));
}
return source;
}
内容来源于网络,如有侵权,请联系作者删除!