本文整理匯總了Java中org.dom4j.Element.attributes方法的典型用法代碼示例。如果您正苦於以下問題:Java Element.attributes方法的具體用法?Java Element.attributes怎麽用?Java Element.attributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.dom4j.Element
的用法示例。
在下文中一共展示了Element.attributes方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: element2Map
import org.dom4j.Element; //導入方法依賴的package包/類
/**
* Element to map
* @param e
* @param map
*/
public static void element2Map(Element e, Map<String, Object> map) {
List<Object> list = e.elements();
if (e.attributeCount() > 0) {
for (Object attri : e.attributes()) {
Attribute at = (Attribute)attri;
map.put(at.getName(), at.getValue());
}
}
if (list.size() < 1 && DataUtil.isEmpty(e.getText())) {
return;
} else if (list.size() < 1 && !DataUtil.isEmpty(e.getText())) {
map.put("text", e.getText());
}
for (Object aList : list) {
Element iter = (Element)aList;
Map<String, Object> cMap = new HashMap<String, Object>();
element2Map(iter, cMap);
map.put(iter.getName(), cMap);
}
}
示例2: element2Map
import org.dom4j.Element; //導入方法依賴的package包/類
/**
* Element to map
*
* @param e
* @return
*/
public static void element2Map(Element e, Map<String, Object> map) {
List<Object> list = e.elements();
if (e.attributeCount() > 0) {
for (Object attri : e.attributes()) {
Attribute at = (Attribute) attri;
map.put(at.getName(), at.getValue());
}
}
if (list.size() < 1 && DataUtil.isEmpty(e.getText())) {
return;
} else if (list.size() < 1 && !DataUtil.isEmpty(e.getText())) {
map.put("text", e.getText());
}
for (Object aList : list) {
Element iter = (Element) aList;
Map<String, Object> cMap = new HashMap<String, Object>();
element2Map(iter, cMap);
map.put(iter.getName(), cMap);
}
}
示例3: getVersionName
import org.dom4j.Element; //導入方法依賴的package包/類
/**
* Update the plug-in's minSdkVersion and targetSdkVersion
*
* @param androidManifestFile
* @throws IOException
* @throws DocumentException
*/
public static String getVersionName(File androidManifestFile) throws IOException, DocumentException {
SAXReader reader = new SAXReader();
String versionName = "";
if (androidManifestFile.exists()) {
Document document = reader.read(androidManifestFile);// Read the XML file
Element root = document.getRootElement();// Get the root node
if ("manifest".equalsIgnoreCase(root.getName())) {
List<Attribute> attributes = root.attributes();
for (Attribute attr : attributes) {
if (StringUtils.equalsIgnoreCase(attr.getName(), "versionName")) {
versionName = attr.getValue();
}
}
}
}
return versionName;
}
示例4: getVersionCode
import org.dom4j.Element; //導入方法依賴的package包/類
public static String getVersionCode(File androidManifestFile) throws IOException, DocumentException {
SAXReader reader = new SAXReader();
String versionCode = "";
if (androidManifestFile.exists()) {
Document document = reader.read(androidManifestFile);// Read the XML file
Element root = document.getRootElement();// Get the root node
if ("manifest".equalsIgnoreCase(root.getName())) {
List<Attribute> attributes = root.attributes();
for (Attribute attr : attributes) {
if (StringUtils.equalsIgnoreCase(attr.getName(), "versionCode")) {
versionCode = attr.getValue();
}
}
}
}
return versionCode;
}
示例5: fillObj
import org.dom4j.Element; //導入方法依賴的package包/類
/**
* 將指定節點的屬性設置到對象裏麵
* @param obj 對象
* @param element 節點
* @param tempflag 模板化標識
* @return 返回結果
*/
public static <T> T fillObj(T obj, Element element,boolean tempflag){
if(element!=null){
List<Attribute> attributes = element.attributes();
for(Attribute a:attributes){
AnalysisObject.invokeSetter(obj,a.getName(),
tempflag?FreeMarkerUtil.render(a.getValue()):a.getValue());
}
}
return obj;
}
示例6: marshallElement
import org.dom4j.Element; //導入方法依賴的package包/類
private void marshallElement(HierarchicalStreamWriter writer, Element element) {
writer.startNode(element.getName());
for (Attribute attribute: (List<Attribute>)element.attributes())
writer.addAttribute(attribute.getName(), attribute.getValue());
if (element.getText().trim().length() != 0)
writer.setValue(element.getText().trim());
for (Element child: (List<Element>)element.elements())
marshallElement(writer, child);
writer.endNode();
}
示例7: manageAttributeInfo
import org.dom4j.Element; //導入方法依賴的package包/類
/**
* Manage all Attribute in a Node
*
* @param node
* Node to Manage
* @param subNode
* Sub Node or not
*/
@SuppressWarnings("unchecked")
private void manageAttributeInfo(final Element node, final boolean subNode)
{
final String startVorString = (subNode == false) ? "! Start Node -- ": "! Start SubNode -- ";
final String startHinString = (subNode == false) ? " -- Start Node ! ": " -- Start SubNode !";
final String endVorString = (subNode == false) ? "! End Node -- ": "! End SubNode -- ";
final String endHinString = (subNode == false) ? " -- End Node !": " -- End SubNode !";
System.out.println("! ----------------------------------------------- !");
System.out.println(startVorString + node.getName() + startHinString);
final List<Attribute> list = node.attributes();
for (final Attribute attr : list)
{
//System.out.println(attr.getText() + "\n" );
System.out.println(" = > " + attr.getName() + " = " + attr.getValue() + ";" );
//Do something to match related information in Node
}
if (!(node.getTextTrim().equals("")))
{
System.out.println("Text: " + node.getText());
}
System.out.println(endVorString + node.getName() + endHinString);
System.out.println("! ----------------------------------------------- !\n");
}
示例8: buildCommonGraphCellElement
import org.dom4j.Element; //導入方法依賴的package包/類
protected void buildCommonGraphCellElement(Element element,Element targetElement){
for(Object obj:element.attributes()){
Attribute attr=(Attribute)obj;
String name=attr.getName();
if(name.equals("name") || name.equals("g")){
continue;
}
targetElement.addAttribute(attr.getName(),attr.getValue());
}
}
示例9: addExtLinkToNetwork
import org.dom4j.Element; //導入方法依賴的package包/類
/**
* 添加外部連接到路網
* @param extLinkList
*/
@SuppressWarnings("unchecked")
private void addExtLinkToNetwork(List<Element> extLinkList)
{
final int extLinkListSize = extLinkList.size();
System.out.println("ExtLink's count: " + extLinkListSize);
for(int i = 0; i<extLinkListSize; i++)
{
//Get a node from the node list
Element element = extLinkList.get(i);
List<Attribute> listExtLinkAttribute = element.attributes();
String id = listExtLinkAttribute.get(0).getValue();
//String fromJunction = listExtLinkAttribute.get(1).getValue();
//String toJunction = listExtLinkAttribute.get(2).getValue();
String numLanes = listExtLinkAttribute.get(3).getValue();
String speed = listExtLinkAttribute.get(4).getValue();
String length = listExtLinkAttribute.get(5).getValue();
Vertex linkStartNodeVertex = null; //連接的起點
Vertex linkEndNodeVertex = null; //連接的終點
List<Element> extConnectionList = element.selectNodes(LocalXmlAttributeMatch.EXTCONNECTION);
//int numExtConnection = extConnectionList.size();
List<Attribute> listExtConnectionAttribute = extConnectionList.get(0).attributes();
String fromNode = listExtConnectionAttribute.get(0).getValue(); //外部連接內部起點
String from_x = listExtConnectionAttribute.get(1).getValue(); //起點X坐標
String from_y = listExtConnectionAttribute.get(2).getValue(); //起點Y坐標
String toNode = listExtConnectionAttribute.get(3).getValue(); //外部連接內部終點
String to_x = listExtConnectionAttribute.get(4).getValue(); //終點X坐標
String to_y = listExtConnectionAttribute.get(5).getValue(); //終點Y坐標
String dir = listExtConnectionAttribute.get(6).getValue(); //轉向信息
linkStartNodeVertex = new Vertex(fromNode,"Internal",
Double.parseDouble(from_x),
Double.parseDouble(from_y));
linkEndNodeVertex = new Vertex(toNode,"Internal",
Double.parseDouble(to_x),
Double.parseDouble(to_y));
//添加外部連接到路網
//-----------------------------------------------------------
Link link = new Link(linkStartNodeVertex, linkEndNodeVertex);
link.setDirection(dir);
link.setName(id);
link.setLaneCount(Integer.parseInt(numLanes));
link.setLinkType("External");
link.setSpeed(Double.parseDouble(speed));
link.setLength(Double.parseDouble(length));
network.addLink(link);
}
}
示例10: addJunctionToNetwork
import org.dom4j.Element; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private void addJunctionToNetwork(List<Element> junctionList)
{
final int junctionListSize = junctionList.size();
System.out.println("Junction's count: " + junctionListSize);
for(int i = 0; i<junctionListSize; i++)
{
Junction junction = null;
//Get a Junction from the Junction List
Element element = junctionList.get(i);
List<Attribute> listJunctionAttribute = element.attributes();
String id = listJunctionAttribute.get(0).getValue();
String type = listJunctionAttribute.get(1).getValue();
String x = listJunctionAttribute.get(2).getValue();
String y = listJunctionAttribute.get(3).getValue();
String intNode = listJunctionAttribute.get(4).getValue();
junction = new Junction(id);//設置路口名
junction.setType(type); //設置路口類型
junction.setX_Coordinate(Double.parseDouble(x));//設置路口X坐標
junction.setY_Coordinate(Double.parseDouble(y));//設置路口Y坐標
//添加內部節點到路口
//---------------------------------------------------
intNode = intNode.replace("[", "");
intNode = intNode.replace("]", "");
String[]intNodes = intNode.split(", ");
for(int p=0; p<intNodes.length; p++)
{
String[] node = intNodes[p].split(" ");
Vertex interNode = null;//內部連接的點
interNode = new Vertex(node[0],"Internal",
Double.parseDouble(node[1]),
Double.parseDouble(node[2]));
junction.addInternalNode(interNode);
}
//添加內部連接到路口
//-----------------------------------------------------
List<Element> intLinkList = element.selectNodes(LocalXmlAttributeMatch.INTCONNECTION);
int numIntLink = intLinkList.size();
for(int j = 0; j<numIntLink; j++)
{
List<Attribute> listIntLinkAttribute = intLinkList.get(j).attributes();
String intLinkID = listIntLinkAttribute.get(0).getValue(); //內部連接名
String intLinkNumLanes = listIntLinkAttribute.get(1).getValue();//車道數
String intLinkFrom = listIntLinkAttribute.get(2).getValue(); //起點
String intLinkFromX = listIntLinkAttribute.get(3).getValue(); //起點X坐標
String intLinkFromY = listIntLinkAttribute.get(4).getValue(); //起點Y坐標
String intLinkTo = listIntLinkAttribute.get(5).getValue(); //終點
String intLinkToX = listIntLinkAttribute.get(6).getValue(); //終點X坐標
String intLinkToY = listIntLinkAttribute.get(7).getValue(); //終點Y坐標
String dir = listIntLinkAttribute.get(8).getValue(); //轉向信息
Vertex interFromNode = null;//內部連接的點
interFromNode = new Vertex(intLinkFrom,"Internal",
Double.parseDouble(intLinkFromX),
Double.parseDouble(intLinkFromY));
Vertex interToNode = null;//內部連接的點
interToNode = new Vertex(intLinkTo,"Internal",
Double.parseDouble(intLinkToX),
Double.parseDouble(intLinkToY));
junction.addInternalEdge(interFromNode, interToNode);
//添加內部連接到路口
//---------------------------------------------------
Link link = new Link(interFromNode,interToNode);
link.setName(intLinkID);
link.setLinkType("Internal");
link.setLaneCount(Integer.parseInt(intLinkNumLanes));
link.setDirection(dir);
network.addLink(link);
}
//添加路口到網絡
network.addJunction(junction);
}
}
示例11: addExtLinkToNetwork
import org.dom4j.Element; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private void addExtLinkToNetwork(List<Element> extLinkList)
{
final int extLinkListSize = extLinkList.size();
System.out.println("ExtLink's count: " + extLinkListSize);
for(int i = 0; i<extLinkListSize; i++)
{
//Get a node from the node list
Element element = extLinkList.get(i);
List<Attribute> listExtLinkAttribute = element.attributes();
String id = listExtLinkAttribute.get(0).getValue();
//String fromJunction = listExtLinkAttribute.get(1).getValue();
//String toJunction = listExtLinkAttribute.get(2).getValue();
String numLanes = listExtLinkAttribute.get(3).getValue();
String speed = listExtLinkAttribute.get(4).getValue();
String length = listExtLinkAttribute.get(5).getValue();
Vertex linkStartNodeVertex = null;//連接的起點
Vertex linkEndNodeVertex = null; //連接的終點
List<Element> extConnectionList = element.selectNodes(LocalXmlAttributeMatch.EXTCONNECTION);
//int numExtConnection = extConnectionList.size();
List<Attribute> listExtConnectionAttribute = extConnectionList.get(0).attributes();
String fromNode = listExtConnectionAttribute.get(0).getValue();//外部連接內部起點
String from_x = listExtConnectionAttribute.get(1).getValue(); //起點X坐標
String from_y = listExtConnectionAttribute.get(2).getValue(); //起點Y坐標
String toNode = listExtConnectionAttribute.get(3).getValue(); //外部連接內部終點
String to_x = listExtConnectionAttribute.get(4).getValue(); //終點X坐標
String to_y = listExtConnectionAttribute.get(5).getValue(); //終點Y坐標
String dir = listExtConnectionAttribute.get(6).getValue(); //轉向信息
linkStartNodeVertex = new Vertex(fromNode,"Internal",
Double.parseDouble(from_x),
Double.parseDouble(from_y));
linkEndNodeVertex = new Vertex(toNode,"Internal",
Double.parseDouble(to_x),
Double.parseDouble(to_y));
//添加外部連接到路網
//-----------------------------------------------------------
Link link = new Link(linkStartNodeVertex, linkEndNodeVertex);
link.setDirection(dir);
link.setName(id);
link.setLaneCount(Integer.parseInt(numLanes));
link.setLinkType("External");
link.setSpeed(Double.parseDouble(speed));
link.setLength(Double.parseDouble(length));
network.addLink(link);
}
}
示例12: saveJunctionAttributeValues
import org.dom4j.Element; //導入方法依賴的package包/類
/**
* Analysis Information in a Node
*
* @param matrix
* Information will be stored in the Matrix
* @param nodeToAnalysis
* Node To Analysis
* @param nodeList
* Node List
* @param matchAttributeList
*/
@SuppressWarnings("unchecked")
public void saveJunctionAttributeValues(Matrix matrix,
final String nodeToAnalysis,
final List<Element> nodeList,
final List<String> matchAttributeList)
{
final int nodeListSize = nodeList.size();
System.out.println(nodeToAnalysis +" \'s count: " + nodeListSize);
for(int i = 0; i<nodeListSize; i++)
{
//Get a node from the node list
final Element element = nodeList.get(i);
//match attribute information
//System.out.println("! ----------------------------------------------- !");
//System.out.println("! Start Node -- " + element.getName() + " -- Start Node !");
final List<Attribute> listAttribute = element.attributes();
Map<String, String> mapCurrently = new HashMap<String, String>();
for (final Attribute attr : listAttribute)
{
//Save all Attribute and it's Value in a Key-Value Map
mapCurrently.put(attr.getName(),attr.getValue());
}
if(nodeToAnalysis.equals(SumoXmlAttributeMatch.JUNCTION))
{
String matchAttribute = "";
//Match all demanded Attributes
for(int j = 0; j<matchAttributeList.size(); j++)
{
matchAttribute = matchAttributeList.get(j);
if(mapCurrently.containsKey(matchAttribute))
{
final String attributeValue = mapCurrently.get(matchAttribute);
//System.out.println(" = > " + matchAttribute + " = " + attributeValue + ";" );
matrix.setAsObject(attributeValue, i,j);
}
}
}
//System.out.println("! End Node -- " + element.getName() + " -- End Node !");
//System.out.println("! ----------------------------------------------- !\n");
}
}
示例13: saveEdgeAttributeValues
import org.dom4j.Element; //導入方法依賴的package包/類
/**
* Analysis Information in a Node
*
* @param matrix
* Information will be stored in the Matrix
* @param nodeToAnalysis
* Node To Analysis
* @param nodeList
* Node List
* @param matchAttributeList
*/
@SuppressWarnings("unchecked")
public void saveEdgeAttributeValues(Matrix matrix,
final String nodeToAnalysis,
final List<Element> nodeList,
final List<String> matchAttributeList)
{
final int nodeListSize = nodeList.size();
System.out.println(nodeToAnalysis +" \'s count: " + nodeListSize);
for(int i = 0; i<nodeListSize; i++)
{
//Get a node from the node list
final Element element = nodeList.get(i);
//match attribute information
//System.out.println("! ----------------------------------------------- !");
//System.out.println("! Start Node -- " + element.getName() + " -- Start Node !");
final List<Attribute> listAttribute = element.attributes();
Map<String, String> mapCurrently = new HashMap<String, String>();
for (final Attribute attr : listAttribute)
{
//Save all Attribute and it's Value in a Key-Value Map
mapCurrently.put(attr.getName(),attr.getValue());
}
if(nodeToAnalysis.equals(SumoXmlAttributeMatch.EDGE))
{
//Sub Node
String start_node = mapCurrently.get("from") + "@" + mapCurrently.get("id");
String end_node = mapCurrently.get("to") + "@" + mapCurrently.get("id");
double speed = 0, length = 0, start_x = 0, start_y = 0, end_x = 0, end_y = 0;
final List<Element> subNodeList = element.selectNodes("lane");
int numLanes = subNodeList.size();
for(int p = 0; p<numLanes; p++)
{
speed += Double.parseDouble(subNodeList.get(p).attribute("speed").getValue());
length += Double.parseDouble(subNodeList.get(p).attribute("length").getValue());
final String[] shape = subNodeList.get(p).attribute("shape").getValue().split(",| ");
start_x += Double.parseDouble(shape[0]);
start_y += Double.parseDouble(shape[1]);
end_x += Double.parseDouble(shape[shape.length-2]);
end_y += Double.parseDouble(shape[shape.length-1]);
}
speed /= numLanes;
length /= numLanes;
start_x /= numLanes;
start_y /= numLanes;
end_x /= numLanes;
end_y /= numLanes;
matrix.setAsObject(mapCurrently.get("id"), i,0);
matrix.setAsObject(mapCurrently.get("from"), i,1);
matrix.setAsObject(mapCurrently.get("to"), i,2);
matrix.setAsObject(Integer.toString(numLanes), i,3);
matrix.setAsObject(Double.toString(speed), i,4);
matrix.setAsObject(Double.toString(length), i,5);
matrix.setAsObject(start_node, i,6);
matrix.setAsObject(Double.toString(start_x), i,7);
matrix.setAsObject(Double.toString(start_y), i,8);
matrix.setAsObject(end_node, i,9);
matrix.setAsObject(Double.toString(end_x), i,10);
matrix.setAsObject(Double.toString(end_y), i,11);
}
//System.out.println("! End Node -- " + element.getName() + " -- End Node !");
//System.out.println("! ----------------------------------------------- !\n");
}
}
示例14: saveConnectionAttributeValues
import org.dom4j.Element; //導入方法依賴的package包/類
/**
* Analysis Information in a Node
*
* @param matrix
* Information will be stored in the Matrix
* @param nodeToAnalysis
* Node To Analysis
* @param nodeList
* Node List
* @param matchAttributeList
*/
@SuppressWarnings("unchecked")
public void saveConnectionAttributeValues(Matrix matrix,
final String nodeToAnalysis,
final List<Element> nodeList,
final List<String> matchAttributeList)
{
final int nodeListSize = nodeList.size();
System.out.println(nodeToAnalysis +" \'s count: " + nodeListSize);
for(int i = 0; i<nodeListSize; i++)
{
//Get a node from the node list
final Element element = nodeList.get(i);
//match attribute information
//System.out.println("! ----------------------------------------------- !");
//System.out.println("! Start Node -- " + element.getName() + " -- Start Node !");
final List<Attribute> listAttribute = element.attributes();
Map<String, String> mapCurrently = new HashMap<String, String>();
for (final Attribute attr : listAttribute)
{
//Save all Attribute and it's Value in a Key-Value Map
mapCurrently.put(attr.getName(),attr.getValue());
}
if(nodeToAnalysis.equals(SumoXmlAttributeMatch.CONNECTION))
{
String matchAttribute = "";
//Match all demanded Attributes
for(int j = 0; j<matchAttributeList.size(); j++)
{
matchAttribute = matchAttributeList.get(j);
if(mapCurrently.containsKey(matchAttribute))
{
final String attributeValue = mapCurrently.get(matchAttribute);
//System.out.println(" = > " + matchAttribute + " = " + attributeValue + ";" );
matrix.setAsObject(attributeValue, i,j);
}
}
}
//System.out.println("! End Node -- " + element.getName() + " -- End Node !");
//System.out.println("! ----------------------------------------------- !\n");
}
}