本文整理匯總了Java中org.w3c.dom.Node.getAttributes方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.getAttributes方法的具體用法?Java Node.getAttributes怎麽用?Java Node.getAttributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.getAttributes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parseTable
import org.w3c.dom.Node; //導入方法依賴的package包/類
protected void parseTable(Node n)
{
NamedNodeMap attrs = n.getAttributes();
String name = attrs.getNamedItem("name").getNodeValue();
if (name.charAt(0) != '#') throw new IllegalArgumentException("Table name must start with #");
StringTokenizer data = new StringTokenizer(n.getFirstChild().getNodeValue());
List<String> array = new ArrayList<>();
while (data.hasMoreTokens())
array.add(data.nextToken());
String[] res = new String[array.size()];
int i = 0;
for (String str : array)
{
res[i++] = str;
}
setTable(name, res);
}
示例2: compareElementNode
import org.w3c.dom.Node; //導入方法依賴的package包/類
static boolean compareElementNode(@NonNull Node node1, @NonNull Node node2, boolean strict) {
if (!node1.getNodeName().equals(node2.getNodeName())) {
return false;
}
NamedNodeMap attr1 = node1.getAttributes();
NamedNodeMap attr2 = node2.getAttributes();
if (!compareAttributes(attr1, attr2)) {
return false;
}
if (strict) {
return compareChildren(node1.getChildNodes(), node2.getChildNodes());
}
return compareContent(node1.getChildNodes(), node2.getChildNodes());
}
示例3: getAttributeValue
import org.w3c.dom.Node; //導入方法依賴的package包/類
static int getAttributeValue(Node node,
NamedNodeMap attrs,
String name,
int min,
int max,
boolean required)
throws IIOInvalidTreeException {
if (attrs == null) {
attrs = node.getAttributes();
}
String valueString = attrs.getNamedItem(name).getNodeValue();
int value = -1;
if (valueString == null) {
if (required) {
throw new IIOInvalidTreeException
(name + " attribute not found", node);
}
} else {
value = Integer.parseInt(valueString);
if ((value < min) || (value > max)) {
throw new IIOInvalidTreeException
(name + " attribute out of range", node);
}
}
return value;
}
示例4: parseXml
import org.w3c.dom.Node; //導入方法依賴的package包/類
@Override
public void parseXml(Node node) {
super.parseXml(node);
NamedNodeMap map=node.getAttributes();
Node lockmodeNode=map.getNamedItem("lockmode");
if(lockmodeNode!=null){
LockModeType type=null;
for(LockModeType mode:LockModeType.values()){
if(mode.toString().equals(lockmodeNode.getNodeValue())){
type=mode;
}
}
this.lockmode=type;
}
Node multiplicityNode=map.getNamedItem("multiplicity");
if(multiplicityNode!=null){
this.multiplicity=multiplicityNode.getNodeValue();
}
}
示例5: parsePluralsValue
import org.w3c.dom.Node; //導入方法依賴的package包/類
private ResourceValue parsePluralsValue(PluralsResourceValue value) {
NodeList children = mValue.getChildNodes();
for (int i = 0, n = children.getLength(); i < n; i++) {
Node child = children.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
NamedNodeMap attributes = child.getAttributes();
String quantity = getAttributeValue(attributes, ATTR_QUANTITY);
if (quantity != null) {
String text = getTextNode(child.getChildNodes());
text = ValueXmlHelper.unescapeResourceString(text, false, true);
value.addPlural(quantity, text);
}
}
}
return value;
}
示例6: testGetValue
import org.w3c.dom.Node; //導入方法依賴的package包/類
public void testGetValue () throws Exception {
Color c = new Color (16, 16, 16);
System.out.println("original "+c);
XMLPropertyEditor propEd = new ColorEditor();
propEd.setValue(c);
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Node element = propEd.storeToXML(doc);
NamedNodeMap nodeMap = element.getAttributes();
for (int i = 0; i < nodeMap.getLength(); i++) {
System.out.println("attr "+i+", "+nodeMap.item(i));
}
propEd.readFromXML(element);
Color restoredColor = (Color)propEd.getValue();
System.out.println("restoredColor "+restoredColor);
assertEquals("Restored value has to be the same", c, restoredColor);
assertTrue("It is Color", restoredColor instanceof Color);
assertFalse("It is not SuperColor", restoredColor instanceof ColorEditor.SuperColor);
System.out.println("GENERATE: " + propEd.getJavaInitializationString ());
assertEquals ("Generate Java source with UI color.", "new java.awt.Color(16, 16, 16)", propEd.getJavaInitializationString ());
}
示例7: parseShortcuts
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Parses a shortcut.
* @param d the node
*/
private void parseShortcuts(Node d)
{
NamedNodeMap attrs = d.getAttributes();
final Node classIdNode = attrs.getNamedItem("classId");
final List<Shortcut> list = new ArrayList<>();
for (Node c = d.getFirstChild(); c != null; c = c.getNextSibling())
{
if ("page".equals(c.getNodeName()))
{
attrs = c.getAttributes();
final int pageId = parseInteger(attrs, "pageId");
for (Node b = c.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("slot".equals(b.getNodeName()))
{
list.add(createShortcut(pageId, b));
}
}
}
}
if (classIdNode != null)
{
_initialShortcutData.put(ClassId.getClassId(Integer.parseInt(classIdNode.getNodeValue())), list);
}
else
{
_initialGlobalShortcutList.addAll(list);
}
}
示例8: extractPolyItem
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Convert polygon element into a path.
*/
private static void extractPolyItem(SvgTree avg, SvgLeafNode child, Node currentGroupNode) {
logger.log(Level.FINE, "Rect found" + currentGroupNode.getTextContent());
if (currentGroupNode.getNodeType() == Node.ELEMENT_NODE) {
NamedNodeMap a = currentGroupNode.getAttributes();
int len = a.getLength();
for (int itemIndex = 0; itemIndex < len; itemIndex++) {
Node n = a.item(itemIndex);
String name = n.getNodeName();
String value = n.getNodeValue();
if (name.equals(SVG_STYLE)) {
addStyleToPath(child, value);
} else if (presentationMap.containsKey(name)) {
child.fillPresentationAttributes(name, value);
} else if (name.equals(SVG_POINTS)) {
PathBuilder builder = new PathBuilder();
String[] split = value.split("[\\s,]+");
float baseX = Float.parseFloat(split[0]);
float baseY = Float.parseFloat(split[1]);
builder.absoluteMoveTo(baseX, baseY);
for (int j = 2; j < split.length; j += 2) {
float x = Float.parseFloat(split[j]);
float y = Float.parseFloat(split[j + 1]);
builder.relativeLineTo(x - baseX, y - baseY);
baseX = x;
baseY = y;
}
builder.relativeClose();
child.setPathData(builder.toString());
}
}
}
}
示例9: getAttributeValue
import org.w3c.dom.Node; //導入方法依賴的package包/類
private static String getAttributeValue(Node node, String attributeName) {
if (node == null) {
return null;
}
NamedNodeMap attribs = node.getAttributes();
if (attribs != null && attribs.getNamedItem(attributeName) != null) { // NOI18N
return attribs.getNamedItem(attributeName).getNodeValue(); // NOI18N
}
return null;
}
示例10: copyNodeAndAttributes
import org.w3c.dom.Node; //導入方法依賴的package包/類
private static final org.w3c.dom.Element copyNodeAndAttributes(Node node) {
org.w3c.dom.Element result = document.createElement(node.getNodeName());
NamedNodeMap attributes = node.getAttributes();
for (int i = 0; i < attributes.getLength(); ++i) {
Node a = attributes.item(i);
String name = a.getNodeName();
String value = a.getNodeValue();
result.setAttribute(name, value);
}
return result;
}
示例11: parseAttributes
import org.w3c.dom.Node; //導入方法依賴的package包/類
protected Properties parseAttributes(Node node) {
Properties attributes = new Properties();
NamedNodeMap nnm = node.getAttributes();
for (int i = 0; i < nnm.getLength(); i++) {
Node attribute = nnm.item(i);
String value = parsePropertyTokens(attribute.getNodeValue());
attributes.put(attribute.getNodeName(), value);
}
return attributes;
}
示例12: getAttribute
import org.w3c.dom.Node; //導入方法依賴的package包/類
public static String getAttribute(Node node, String name) {
NamedNodeMap attributes = node.getAttributes();
if (attributes == null) {
return null;
}
Node attributeNode = node.getAttributes().getNamedItem(name);
if (attributeNode == null) {
return null;
}
return attributeNode.getTextContent();
}
示例13: parseDocument
import org.w3c.dom.Node; //導入方法依賴的package包/類
@Override
public void parseDocument(Document doc, File f)
{
final Node table = doc.getFirstChild();
final NamedNodeMap tableAttr = table.getAttributes();
MAX_LEVEL = (byte) (Byte.parseByte(tableAttr.getNamedItem("maxLevel").getNodeValue()) + 1);
MAX_PET_LEVEL = (byte) (Byte.parseByte(tableAttr.getNamedItem("maxPetLevel").getNodeValue()) + 1);
if (MAX_LEVEL > Config.PLAYER_MAXIMUM_LEVEL)
{
MAX_LEVEL = Config.PLAYER_MAXIMUM_LEVEL;
}
if (MAX_PET_LEVEL > MAX_LEVEL)
{
MAX_PET_LEVEL = MAX_LEVEL; // Pet level should not exceed owner level.
}
int maxLevel = 0;
for (Node n = table.getFirstChild(); n != null; n = n.getNextSibling())
{
if ("experience".equals(n.getNodeName()))
{
final NamedNodeMap attrs = n.getAttributes();
maxLevel = parseInteger(attrs, "level");
if (maxLevel > Config.PLAYER_MAXIMUM_LEVEL)
{
break;
}
_expTable.put(maxLevel, parseLong(attrs, "tolevel"));
}
}
}
示例14: setPropsForCompileFile
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Description: Editing the xml file for compiling files.
* @param init path to the xml file
* @param sourceFile path to the source to be compiled
*/
public static void setPropsForCompileFile(String init, String sourceFile) {
try {
File file = new File(sourceFile);
String filepath = init;
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(filepath);
// get project
//Node project = doc.getFirstChild();
Node prop1 = doc.getElementsByTagName("property").item(0);
Node prop2 = doc.getElementsByTagName("property").item(1);
Node prop3 = doc.getElementsByTagName("property").item(2);
NamedNodeMap srcAttr = prop1.getAttributes();
Node srcName = srcAttr.getNamedItem("location");
srcName.setTextContent( file.getParent());
NamedNodeMap buildAttr = prop2.getAttributes();
Node buildName = buildAttr.getNamedItem("location");
buildName.setTextContent( file.getParent());
NamedNodeMap fileAttr = prop3.getAttributes();
Node fileName = fileAttr.getNamedItem("value");
fileName.setTextContent( file.getName());
updateBuildFile( filepath, doc);
} catch (Exception ex) {}
}
示例15: Htable
import org.w3c.dom.Node; //導入方法依賴的package包/類
Htable(Node node) throws IIOInvalidTreeException {
if (node.getNodeName().equals("dhtable")) {
NamedNodeMap attrs = node.getAttributes();
int count = attrs.getLength();
if (count != 2) {
throw new IIOInvalidTreeException
("dhtable node must have 2 attributes", node);
}
tableClass = getAttributeValue(node, attrs, "class", 0, 1, true);
tableID = getAttributeValue(node, attrs, "htableId", 0, 3, true);
if (node instanceof IIOMetadataNode) {
IIOMetadataNode ourNode = (IIOMetadataNode) node;
JPEGHuffmanTable table =
(JPEGHuffmanTable) ourNode.getUserObject();
if (table == null) {
throw new IIOInvalidTreeException
("dhtable node must have user object", node);
}
numCodes = table.getLengths();
values = table.getValues();
} else {
throw new IIOInvalidTreeException
("dhtable node must have user object", node);
}
} else {
throw new IIOInvalidTreeException
("Invalid node, expected dqtable", node);
}
}