本文整理了Java中org.jsoup.nodes.Element.<init>()
方法的一些代码示例,展示了Element.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.<init>()
方法的具体详情如下:
包路径:org.jsoup.nodes.Element
类名称:Element
方法名:<init>
[英]Create a new, standalone element.
[中]创建一个新的独立元素。
代码示例来源:origin: org.jsoup/jsoup
@Override
public Element shallowClone() {
// simpler than implementing a clone version with no child copy
return new Element(tag, baseUri, attributes);
}
代码示例来源:origin: org.jsoup/jsoup
/**
Create a new Element, with this document's base uri. Does not make the new element a child of this document.
@param tagName element tag name (e.g. {@code a})
@return new element
*/
public Element createElement(String tagName) {
return new Element(Tag.valueOf(tagName, ParseSettings.preserveCase), this.baseUri());
}
代码示例来源:origin: org.jsoup/jsoup
Element insertStartTag(String startTagName) {
Element el = new Element(Tag.valueOf(startTagName, settings), baseUri);
insert(el);
return el;
}
代码示例来源:origin: jooby-project/jooby
/**
* Read a svg file and return the svg element (original) and a new symbol element (created from
* original).
*
* @param file Svg file.
* @param id ID to use.
* @return Svg element (original) and a symbol element (converted).
* @throws IOException If something goes wrong.
*/
private Tuple<Element, Element> symbol(final Path file, final String id) throws IOException {
Element svg = Jsoup.parse(file.toFile(), "UTF-8").select("svg").first();
Element symbol = new Element(Tag.valueOf("symbol"), "")
.attr("id", id)
.attr("viewBox", svg.attr("viewBox"));
new ArrayList<>(svg.childNodes()).forEach(symbol::appendChild);
return new Tuple(svg, symbol);
}
代码示例来源:origin: org.jsoup/jsoup
/**
* Create a new element by tag name, and add it as the first child.
*
* @param tagName the name of the tag (e.g. {@code div}).
* @return the new element, to allow you to add content to it, e.g.:
* {@code parent.prependElement("h1").attr("id", "header").text("Welcome");}
*/
public Element prependElement(String tagName) {
Element child = new Element(Tag.valueOf(tagName), baseUri());
prependChild(child);
return child;
}
代码示例来源:origin: org.jsoup/jsoup
/**
* Create a new element by tag name, and add it as the last child.
*
* @param tagName the name of the tag (e.g. {@code div}).
* @return the new element, to allow you to add content to it, e.g.:
* {@code parent.appendElement("h1").attr("id", "header").text("Welcome");}
*/
public Element appendElement(String tagName) {
Element child = new Element(Tag.valueOf(tagName), baseUri());
appendChild(child);
return child;
}
代码示例来源:origin: jooby-project/jooby
@Override
public void run(final Config conf) throws Exception {
String input = get("input");
if (input == null) {
throw new IllegalArgumentException("Required option 'svg-symbol.input' not present");
}
Path basedir = Paths.get(get("basedir").toString());
Path dir = basedir.resolve(input);
List<CharSequence> cssout = new ArrayList<>();
Element svg = new Element(Tag.valueOf("svg"), "");
attrs("svg", "output").forEach((n, v) -> svg.attr(n, v.toString()));
files(dir, file -> {
log.debug("{}", file);
String id = get("id.prefix") + file.getFileName().toString().replace(".svg", "")
+ get("id.suffix");
Tuple<Element, Element> rewrite = symbol(file, id);
svg.appendChild(rewrite._2);
cssout.add(css(id, rewrite._1));
});
write(basedir.resolve(svgPath()), ImmutableList.of(svg.outerHtml()));
write(basedir.resolve(cssPath()), cssout);
}
代码示例来源:origin: org.jsoup/jsoup
Element insert(Token.StartTag startTag) {
Tag tag = Tag.valueOf(startTag.name(), settings);
// todo: wonder if for xml parsing, should treat all tags as unknown? because it's not html.
Element el = new Element(tag, baseUri, settings.normalizeAttributes(startTag.attributes));
insertNode(el);
if (startTag.isSelfClosing()) {
if (!tag.isKnownTag()) // unknown tag, remember this is self closing for output. see above.
tag.setSelfClosing();
} else {
stack.add(el);
}
return el;
}
代码示例来源:origin: org.jsoup/jsoup
Element insert(Token.StartTag startTag) {
// handle empty unknown tags
// when the spec expects an empty tag, will directly hit insertEmpty, so won't generate this fake end tag.
if (startTag.isSelfClosing()) {
Element el = insertEmpty(startTag);
stack.add(el);
tokeniser.transition(TokeniserState.Data); // handles <script />, otherwise needs breakout steps from script data
tokeniser.emit(emptyEnd.reset().name(el.tagName())); // ensure we get out of whatever state we are in. emitted for yielded processing
return el;
}
Element el = new Element(Tag.valueOf(startTag.name(), settings), baseUri, settings.normalizeAttributes(startTag.attributes));
insert(el);
return el;
}
代码示例来源:origin: org.jsoup/jsoup
Element insertEmpty(Token.StartTag startTag) {
Tag tag = Tag.valueOf(startTag.name(), settings);
Element el = new Element(tag, baseUri, startTag.attributes);
insertNode(el);
if (startTag.isSelfClosing()) {
if (tag.isKnownTag()) {
if (!tag.isEmpty())
tokeniser.error("Tag cannot be self closing; not a void tag");
}
else // unknown tag, remember this is self closing for output
tag.setSelfClosing();
}
return el;
}
代码示例来源:origin: org.jsoup/jsoup
private ElementMeta createSafeElement(Element sourceEl) {
String sourceTag = sourceEl.tagName();
Attributes destAttrs = new Attributes();
Element dest = new Element(Tag.valueOf(sourceTag), sourceEl.baseUri(), destAttrs);
int numDiscarded = 0;
Attributes sourceAttrs = sourceEl.attributes();
for (Attribute sourceAttr : sourceAttrs) {
if (whitelist.isSafeAttribute(sourceTag, sourceEl, sourceAttr))
destAttrs.put(sourceAttr);
else
numDiscarded++;
}
Attributes enforcedAttrs = whitelist.getEnforcedAttributes(sourceTag);
destAttrs.addAll(enforcedAttrs);
return new ElementMeta(dest, numDiscarded);
}
代码示例来源:origin: org.jsoup/jsoup
root = new Element(Tag.valueOf("html", settings), baseUri);
doc.appendChild(root);
stack.add(root);
代码示例来源:origin: k9mail/k-9
public void head(Node source, int depth) {
if (elementToSkip != null) {
return;
}
if (source instanceof Element) {
Element sourceElement = (Element) source;
if (isSafeTag(sourceElement)) {
String sourceTag = sourceElement.tagName();
Attributes destinationAttributes = sourceElement.attributes().clone();
Element destinationChild = new Element(Tag.valueOf(sourceTag), sourceElement.baseUri(), destinationAttributes);
destination.appendChild(destinationChild);
destination = destinationChild;
} else if (source != root) {
elementToSkip = sourceElement;
}
} else if (source instanceof TextNode) {
TextNode sourceText = (TextNode) source;
TextNode destinationText = new TextNode(sourceText.getWholeText(), source.baseUri());
destination.appendChild(destinationText);
} else if (source instanceof DataNode && isSafeTag(source.parent())) {
DataNode sourceData = (DataNode) source;
DataNode destinationData = new DataNode(sourceData.getWholeData(), source.baseUri());
destination.appendChild(destinationData);
}
}
代码示例来源:origin: org.jsoup/jsoup
break;
Element replacement = new Element(Tag.valueOf(node.nodeName(), ParseSettings.preserveCase), tb.getBaseUri());
Element adopter = new Element(formatEl.tag(), tb.getBaseUri());
adopter.attributes().addAll(formatEl.attributes());
Node[] childNodes = furthestBlock.childNodes().toArray(new Node[furthestBlock.childNodeSize()]);
代码示例来源:origin: com.vaadin/vaadin-server
@Override
public void writeDesign(Element design, DesignContext designContext) {
super.writeDesign(design, designContext);
Element popupContent = new Element(Tag.valueOf("popup-content"), "");
popupContent.appendChild(
designContext.createElement(content.getPopupComponent()));
String minimizedHTML = content.getMinimizedValueAsHTML();
if (minimizedHTML != null && !minimizedHTML.isEmpty()) {
design.append(minimizedHTML);
}
design.appendChild(popupContent);
}
代码示例来源:origin: com.vaadin/vaadin-server
.getFragmentNodes();
Element mainDiv = new Element(Tag.valueOf("div"), "");
mainDiv.attr("id", context.getAppId());
mainDiv.addClass("v-app");
fragmentNodes.add(new Element(Tag.valueOf("script"), "")
.attr("type", "text/javascript").attr("src", pushJS));
fragmentNodes.add(new Element(Tag.valueOf("script"), "")
.attr("type", "text/javascript")
.attr("src", bootstrapLocation));
Element mainScriptTag = new Element(Tag.valueOf("script"), "")
.attr("type", "text/javascript");
代码示例来源:origin: com.vaadin/flow-server
private static Element createHtmlImportElement(String url) {
final Element htmlImportElement;
if (url != null) {
htmlImportElement = new Element(Tag.valueOf("link"), "")
.attr("rel", "import").attr("href", url);
} else {
htmlImportElement = new Element(Tag.valueOf("span"), "")
.attr("hidden", true);
}
return htmlImportElement;
}
代码示例来源:origin: com.vaadin/vaadin-server
protected Element createMenuElement(MenuItem item, DesignContext context) {
Element menuElement = new Element(Tag.valueOf("menu"), "");
代码示例来源:origin: org.kantega.openaksess/openaksess-core
private static Element createSafeElement(Element sourceEl) {
String sourceTag = sourceEl.tagName();
org.jsoup.nodes.Attributes destAttrs = new org.jsoup.nodes.Attributes();
Element dest = new Element(Tag.valueOf(sourceTag), sourceEl.baseUri(), destAttrs);
org.jsoup.nodes.Attributes sourceAttrs = sourceEl.attributes();
for (Attribute sourceAttr : sourceAttrs) {
destAttrs.put(sourceAttr);
}
return dest;
}
代码示例来源:origin: dstl/baleen
@Test
public void testAnchor() throws UIMAException {
final JCas jCas = JCasSingleton.getJCasInstance();
final StructuralAnnotations sa = new StructuralAnnotations();
final Element anchor = new Element(Tag.valueOf("a"), "");
final AnnotationCollector collector = new AnnotationCollector();
sa.map(jCas, anchor, collector);
assertTrue(collector.getAnnotations().get(0) instanceof Anchor);
}
内容来源于网络,如有侵权,请联系作者删除!