本文整理了Java中org.jdom2.Element
类的一些代码示例,展示了Element
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element
类的具体详情如下:
包路径:org.jdom2.Element
类名称:Element
[英]An XML element. Methods allow the user to get and manipulate its child elements and content, directly access the element's textual content, manipulate its attributes, and manage namespaces.
See NamespaceAware and #getNamespacesInScope() for more details on what the Namespace scope is and how it is managed in JDOM and specifically by this Element class.
[中]XML元素。方法允许用户获取和操作其子元素和内容,直接访问元素的文本内容,操作其属性,以及管理名称空间。
请参阅NamespaceAware和#GetNamespacesInsScope(),以了解有关命名空间作用域的更多详细信息,以及如何在JDOM中管理它,特别是如何由该元素类管理它。
代码示例来源:origin: gocd/gocd
public HashMap<String, String> parseInfoToGetUUID(String output, String queryURL, SAXBuilder builder) {
HashMap<String, String> uidToUrlMap = new HashMap<>();
try {
Document document = builder.build(new StringReader(output));
Element root = document.getRootElement();
List<Element> entries = root.getChildren("entry");
for (Element entry : entries) {
uidToUrlMap.put(queryURL, entry.getChild("repository").getChild("uuid").getValue());
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return uidToUrlMap;
}
代码示例来源:origin: gocd/gocd
private int getCurrentSchemaVersion(String content) {
try {
SAXBuilder builder = new SAXBuilder();
Document document = builder.build(new ByteArrayInputStream(content.getBytes()));
Element root = document.getRootElement();
String currentVersion = root.getAttributeValue(schemaVersion) == null ? "0" : root.getAttributeValue(schemaVersion);
return Integer.parseInt(currentVersion);
} catch (Exception e) {
throw bomb(e);
}
}
代码示例来源:origin: simpligility/android-maven-plugin
@SuppressWarnings( "unchecked" )
private void appendElement( Element source, Element target )
{
for ( Iterator<Attribute> itr = source.getAttributes().iterator(); itr.hasNext(); )
{
Attribute a = itr.next();
itr.remove();
Attribute mergedAtt = target.getAttribute( a.getName(), a.getNamespace() );
if ( mergedAtt == null )
{
target.setAttribute( a );
}
}
for ( Iterator<Element> itr = source.getChildren().iterator(); itr.hasNext(); )
{
Content n = itr.next();
itr.remove();
target.addContent( n );
}
}
代码示例来源:origin: gocd/gocd
private void addBreakers(Element element) {
Element messages = new Element("messages");
Element message = new Element("message");
String breakerNames = StringUtils.join(breakers, ", ");
message.setAttribute("text", breakerNames);
message.setAttribute("kind", "Breakers");
messages.addContent(message);
element.addContent(messages);
}
代码示例来源:origin: gocd/gocd
private void parseDOMTree(Document document) throws UnsupportedEncodingException {
Element infoElement = document.getRootElement();
Element entryElement = infoElement.getChild("entry");
String encodedUrl = entryElement.getChildTextTrim("url");
Element repositoryElement = entryElement.getChild("repository");
String root = repositoryElement.getChildTextTrim("root");
String encodedPath = StringUtils.replace(encodedUrl, root, "");
this.path = URLDecoder.decode(encodedPath, ENCODING);
this.root = root;
this.encodedUrl = encodedUrl;
}
代码示例来源:origin: edu.ucar/netcdf
private void writeOneEntry( InvDataset ds, OutputStream out, StringBuffer mess) throws IOException {
Element rootElem = new Element("DIF", defNS);
Document doc = new Document(rootElem);
writeDataset( ds, rootElem, mess);
rootElem.addNamespaceDeclaration(defNS);
rootElem.addNamespaceDeclaration(XMLEntityResolver.xsiNS);
rootElem.setAttribute("schemaLocation", defNS.getURI()+" "+schemaLocation, XMLEntityResolver.xsiNS);
// Output the document, use standard formatter
XMLOutputter fmt = new XMLOutputter( Format.getPrettyFormat());
fmt.output( doc, out);
}
代码示例来源:origin: jwpttcg66/NettyGameServer
public static void loadFormat(String folderPath, List<MessageObject> list) throws JDOMException, IOException{
File file = FileUtil.getFile(folderPath);
if(!file.exists() || file.isFile()){
return ;
}
folderPath = file.getPath();
String[] xmlFileNames = file.list();
for(String xmlFileName : xmlFileNames){
Document doc = new SAXBuilder().build(new File(folderPath, xmlFileName));
Element root = doc.getRootElement();
if(!"messages".equals(root.getName())){
continue;
}
for(Element message : root.getChildren()){
list.add(new MessageObject(message));
}
}
}
}
代码示例来源:origin: org.cleartk/cleartk-corpus
public GeniaPosParser(File xmlFile) throws IOException, JDOMException {
this();
SAXBuilder builder = new SAXBuilder();
builder.setDTDHandler(null);
root = builder.build(xmlFile).getRootElement();
articles = root.getChildren("article").iterator();
outputter = new XMLOutputter();
}
代码示例来源:origin: rometools/rome
@Override
public boolean isMyType(final Document document) {
final Element rssRoot = document.getRootElement();
final Attribute version = rssRoot.getAttribute("version");
return rssRoot.getName().equals("rss") && version != null && version.getValue().equals(getRSSVersion());
}
代码示例来源:origin: sc.fiji/TrackMate_
private static double[] readCalibration( final File source ) throws JDOMException, IOException
{
final SAXBuilder sb = new SAXBuilder();
final Document document = sb.build( source );
final Element root = document.getRootElement();
final double[] calibration = new double[ 3 ];
final Element settings = root.getChild( "Settings" );
final Element imageData = settings.getChild( "ImageData" );
calibration[ 0 ] = imageData.getAttribute( "pixelwidth" ).getDoubleValue();
calibration[ 1 ] = imageData.getAttribute( "pixelheight" ).getDoubleValue();
calibration[ 2 ] = imageData.getAttribute( "voxeldepth" ).getDoubleValue();
return calibration;
}
代码示例来源:origin: gocd/gocd
private Modification parseLogEntry(Element logEntry, String path) throws ParseException {
Element logEntryPaths = logEntry.getChild("paths");
if (logEntryPaths == null) {
/* Path-based access control forbids us from learning
* details of this log entry, so skip it. */
return null;
}
Date modifiedTime = convertDate(logEntry.getChildText("date"));
String author = logEntry.getChildText("author");
String comment = logEntry.getChildText("msg");
String revision = logEntry.getAttributeValue("revision");
Modification modification = new Modification(author, comment, null, modifiedTime, revision);
List paths = logEntryPaths.getChildren("path");
for (Iterator iterator = paths.iterator(); iterator.hasNext();) {
Element node = (Element) iterator.next();
if (underPath(path, node.getText())) {
ModifiedAction action = convertAction(node.getAttributeValue("action"));
modification.createModifiedFile(node.getText(), null, action);
}
}
return modification;
}
代码示例来源:origin: Unidata/thredds
public void readTable() throws IOException {
org.jdom2.Document doc;
try {
SAXBuilder builder = new SAXBuilder();
doc = builder.build(robbxml);
Element root = doc.getRootElement();
int count = makeTable(root.getChildren("sequence"));
System.out.println(" robb count= "+count);
} catch (JDOMException e) {
throw new IOException(e.getMessage());
}
}
代码示例来源:origin: gocd/gocd
return;
Document document = new SAXBuilder().build(configFile);
List<String> encryptedAttributes = Arrays.asList("encryptedPassword", "encryptedManagerPassword");
List<String> encryptedNodes = Arrays.asList("encryptedValue");
List<Element> encryptedPasswordElements = xpathExpression.evaluate(document);
for (Element element : encryptedPasswordElements) {
Attribute encryptedPassword = element.getAttribute(attributeName);
encryptedPassword.setValue(reEncryptUsingNewKey(decodeHex(oldCipher), decodeHex(newCipher), encryptedPassword.getValue()));
LOGGER.debug("Replaced encrypted value at {}", element.toString());
List<Element> encryptedNode = xpathExpression.evaluate(document);
for (Element element : encryptedNode) {
element.setText(reEncryptUsingNewKey(decodeHex(oldCipher), decodeHex(newCipher), element.getValue()));
LOGGER.debug("Replaced encrypted value at {}", element.toString());
代码示例来源:origin: geotools/geotools
SAXBuilder builder = new SAXBuilder();
builder.setExpandEntities(false);
Document document = builder.build(inputStream);
Element root = document.getRootElement();
List<Element> serviceExceptions = root.getChildren("ServiceException");
代码示例来源:origin: Unidata/thredds
private boolean isGetCoverageWcsDoc(String url) throws JDOMException, IOException {
byte[] result = TestOnLocalServer.getContent(url+baloney+"&request=GetCapabilities", 200, ContentType.xml);
Reader in = new StringReader( new String(result, CDM.utf8Charset));
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build(in);
boolean isName = doc.getRootElement().getName().equals("WCS_Capabilities");
boolean isNamespace = doc.getRootElement().getNamespaceURI().equals(NS_WCS.getURI());
return (isName && isNamespace);
}
代码示例来源:origin: gocd/gocd
@Test
public void shouldListAllArtifactsWhenArtifactsNotPurged() throws Exception {
HtmlRenderer renderer = new HtmlRenderer("context");
DirectoryEntries directoryEntries = new DirectoryEntries();
directoryEntries.add(new FolderDirectoryEntry("cruise-output", "", new DirectoryEntries()));
directoryEntries.add(new FolderDirectoryEntry("some-artifact", "", new DirectoryEntries()));
directoryEntries.render(renderer);
Element document = getRenderedDocument(renderer);
assertThat(document.getChildren().size(), is(2));
Element cruiseOutputElement = (Element) document.getChildren().get(0);
assertThat(cruiseOutputElement.getChild("div").getChild("span").getChild("a").getTextNormalize(), is("cruise-output"));
Element artifactElement = (Element) document.getChildren().get(1);
assertThat(artifactElement.getChild("div").getChild("span").getChild("a").getTextNormalize(), is("some-artifact"));
}
代码示例来源:origin: gocd/gocd
private static Element elementFor(Class<?> aClass, ConfigCache configCache) {
final AttributeAwareConfigTag attributeAwareConfigTag = annotationFor(aClass, AttributeAwareConfigTag.class);
if (attributeAwareConfigTag != null) {
final Element element = new Element(attributeAwareConfigTag.value(), namespaceFor(attributeAwareConfigTag));
element.setAttribute(attributeAwareConfigTag.attribute(), attributeAwareConfigTag.attributeValue());
return element;
}
ConfigTag configTag = annotationFor(aClass, ConfigTag.class);
if (configTag == null)
throw bomb(format("Cannot get config tag for {0}", aClass));
return new Element(configTag.value(), namespaceFor(configTag));
}
代码示例来源:origin: gocd/gocd
public CommandSnippet parse(String xmlContent, String fileName, String relativeFilePath) {
try {
Document document = buildXmlDocument(xmlContent, CommandSnippet.class.getResource("command-snippet.xsd"));
CommandSnippetComment comment = getComment(document);
Element execTag = document.getRootElement();
String commandName = execTag.getAttributeValue("command");
List<String> arguments = new ArrayList<>();
for (Object child : execTag.getChildren()) {
Element element = (Element) child;
arguments.add(element.getValue());
}
return new CommandSnippet(commandName, arguments, comment, fileName, relativeFilePath);
} catch (Exception e) {
String errorMessage = String.format("Reason: %s", e.getMessage());
LOGGER.info("Could not load command '{}'. {}", fileName, errorMessage);
return CommandSnippet.invalid(fileName, errorMessage, new EmptySnippetComment());
}
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
public String peekNextChild() {
List list = currentElement.getChildren();
if (null == list || list.isEmpty()) {
return null;
}
return decodeNode(((Element) list.get(0)).getName());
}
}
代码示例来源:origin: gocd/gocd
private Document createEmptyCruiseConfigDocument() {
Element root = new Element("cruise");
Namespace xsiNamespace = Namespace.getNamespace("xsi", XML_NS);
root.addNamespaceDeclaration(xsiNamespace);
registry.registerNamespacesInto(root);
root.setAttribute("noNamespaceSchemaLocation", "cruise-config.xsd", xsiNamespace);
String xsds = registry.xsds();
if (!xsds.isEmpty()) {
root.setAttribute("schemaLocation", xsds, xsiNamespace);
}
root.setAttribute("schemaVersion", Integer.toString(GoConstants.CONFIG_SCHEMA_VERSION));
return new Document(root);
}
内容来源于网络,如有侵权,请联系作者删除!