本文整理汇总了Java中org.w3c.dom.NamedNodeMap.item方法的典型用法代码示例。如果您正苦于以下问题:Java NamedNodeMap.item方法的具体用法?Java NamedNodeMap.item怎么用?Java NamedNodeMap.item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.NamedNodeMap
的用法示例。
在下文中一共展示了NamedNodeMap.item方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseTransformation
import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
private static void parseTransformation(SvgTree avg, Node nNode) {
NamedNodeMap a = nNode.getAttributes();
int len = a.getLength();
for (int i = 0; i < len; i++) {
Node n = a.item(i);
String name = n.getNodeName();
String value = n.getNodeValue();
if (SVG_TRANSFORM.equals(name)) {
if (value.startsWith("matrix(")) {
value = value.substring("matrix(".length(), value.length() - 1);
String[] sp = value.split(" ");
for (int j = 0; j < sp.length; j++) {
avg.matrix[j] = Float.parseFloat(sp[j]);
}
}
} else if (name.equals("y")) {
Float.parseFloat(value);
} else if (name.equals("x")) {
Float.parseFloat(value);
}
}
}
示例2: parseEquipment
import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
/**
* Parses the equipment.
* @param d parse an initial equipment and add it to {@link #_initialEquipmentList}
*/
private void parseEquipment(Node d)
{
NamedNodeMap attrs = d.getAttributes();
final ClassId classId = ClassId.getClassId(Integer.parseInt(attrs.getNamedItem("classId").getNodeValue()));
final List<PcItemTemplate> equipList = new ArrayList<>();
for (Node c = d.getFirstChild(); c != null; c = c.getNextSibling())
{
if ("item".equalsIgnoreCase(c.getNodeName()))
{
final StatsSet set = new StatsSet();
attrs = c.getAttributes();
for (int i = 0; i < attrs.getLength(); i++)
{
final Node attr = attrs.item(i);
set.set(attr.getNodeName(), attr.getNodeValue());
}
equipList.add(new PcItemTemplate(set));
}
}
_initialEquipmentList.put(classId, equipList);
}
示例3: printNodes
import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
/**
* Only for debug
*
*/
public void printNodes(Node n) {
if (n == null) {
return;
}
String attrs = "";
if (n.getAttributes() != null) {
NamedNodeMap aNodes = n.getAttributes();
for (int i = 0; i < aNodes.getLength(); i++) {
Node item = aNodes.item(i);
attrs = attrs + " " + item.getNodeName() + "=" + item.getNodeValue();
}
}
System.out.println(n.getNodeName() + " = " + n.getNodeValue() + ";\tattrs: " + attrs);
if (n.getChildNodes() == null) {
return;
}
NodeList nl = n.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
printNodes(nl.item(i));
}
}
示例4: initXmlns
import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
protected void initXmlns(Document doc) {
NodeList fictionBook = doc.getElementsByTagName("FictionBook");
List<Node> xmlns = new ArrayList<>();
for (int item = 0; item < fictionBook.getLength(); item++) {
NamedNodeMap map = fictionBook.item(item).getAttributes();
for (int index = 0; index < map.getLength(); index++) {
Node node = map.item(index);
xmlns.add(node);
}
}
setXmlns(xmlns);
}
示例5: parseDocument
import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
@Override
public void parseDocument(Document doc, File f)
{
for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
{
if ("list".equalsIgnoreCase(n.getNodeName()))
{
for (Node cd = n.getFirstChild(); cd != null; cd = cd.getNextSibling())
{
switch (cd.getNodeName())
{
case "schedule":
{
final StatsSet set = new StatsSet();
final NamedNodeMap attrs = cd.getAttributes();
for (int i = 0; i < attrs.getLength(); i++)
{
final Node node = attrs.item(i);
final String key = node.getNodeName();
String val = node.getNodeValue();
if ("day".equals(key))
{
if (!Util.isDigit(val))
{
val = Integer.toString(getValueForField(val));
}
}
set.set(key, val);
}
_scheduleData.add(new SiegeScheduleDate(set));
break;
}
}
}
}
}
}
示例6: test
import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
@Test
public void test() {
try {
FileInputStream fis = new FileInputStream(getClass().getResource("bug6690015.xml").getFile());
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(fis));
Element root = doc.getDocumentElement();
NodeList textnodes = root.getElementsByTagName("text");
int len = textnodes.getLength();
int index = 0;
int attindex = 0;
int attrlen = 0;
NamedNodeMap attrs = null;
while (index < len) {
Element te = (Element) textnodes.item(index);
attrs = te.getAttributes();
attrlen = attrs.getLength();
attindex = 0;
Node node = null;
while (attindex < attrlen) {
node = attrs.item(attindex);
System.out.println("attr: " + node.getNodeName() + " is shown holding value: " + node.getNodeValue());
attindex++;
}
index++;
System.out.println("-------------");
}
fis.close();
} catch (Exception e) {
Assert.fail("Exception: " + e.getMessage());
}
}
示例7: getAttribute
import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
private String getAttribute( Node node, String attributeName )
{
NamedNodeMap attributes = node.getAttributes();
for(int i = 0; i < attributes.getLength(); i++ )
{
Node attributeNode = attributes.item(i);
if( attributeNode.getNodeName().equals(attributeName))
{
return attributeNode.getNodeValue();
}
}
return null;
}
示例8: displayMetadata
import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
void displayMetadata(Node node, int level) {
indent(level); // emit open tag
System.out.print("<" + node.getNodeName());
NamedNodeMap map = node.getAttributes();
if (map != null) { // print attribute values
int length = map.getLength();
for (int i = 0; i < length; i++) {
Node attr = map.item(i);
System.out.print(" " + attr.getNodeName() +
"=\"" + attr.getNodeValue() + "\"");
}
}
Node child = node.getFirstChild();
if (node.getNodeValue() != null && !node.getNodeValue().equals("") ) {
System.out.println(">");
indent(level);
System.out.println(node.getNodeValue());
indent(level); // emit close tag
System.out.println("</" + node.getNodeName() + ">");
} else if (child != null) {
System.out.println(">"); // close current tag
while (child != null) { // emit child tags recursively
displayMetadata(child, level + 1);
child = child.getNextSibling();
}
indent(level); // emit close tag
System.out.println("</" + node.getNodeName() + ">");
} else {
System.out.println("/>");
}
}
示例9: initNamespaceSupport
import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
/**
* Initialize namespace support by collecting all of the namespace
* declarations in the root's ancestors. This is necessary to
* support schemas fragments, i.e. schemas embedded in other
* documents. See,
*
* https://jaxp.dev.java.net/issues/show_bug.cgi?id=43
*
* Requires the DOM to be created with namespace support enabled.
*/
private void initNamespaceSupport(Element schemaRoot) {
fNamespaceSupport = new SchemaNamespaceSupport();
fNamespaceSupport.reset();
Node parent = schemaRoot.getParentNode();
while (parent != null && parent.getNodeType() == Node.ELEMENT_NODE
&& !parent.getNodeName().equals("DOCUMENT_NODE"))
{
Element eparent = (Element) parent;
NamedNodeMap map = eparent.getAttributes();
int length = (map != null) ? map.getLength() : 0;
for (int i = 0; i < length; i++) {
Attr attr = (Attr) map.item(i);
String uri = attr.getNamespaceURI();
// Check if attribute is an ns decl -- requires ns support
if (uri != null && uri.equals("http://www.w3.org/2000/xmlns/")) {
String prefix = attr.getLocalName().intern();
if (prefix == "xmlns") prefix = "";
// Declare prefix if not set -- moving upwards
if (fNamespaceSupport.getURI(prefix) == null) {
fNamespaceSupport.declarePrefix(prefix,
attr.getValue().intern());
}
}
}
parent = parent.getParentNode();
}
}
示例10: attributesToMap
import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
/** Reads the attributes within the input element and adds them to the input Map.
* @param element An Element.
* @param map A Map.
*/
protected void attributesToMap(Element element, Map<String, String> map) {
NamedNodeMap attributes = element.getAttributes();
if (attributes != null) {
for (int i = 0; i < attributes.getLength(); i++) {
Node attribute = attributes.item(i);
if (attribute.getNodeType() == Node.ATTRIBUTE_NODE)
map.put(attribute.getNodeName(), attribute.getNodeValue());
}
}
}
示例11: parseAttributes
import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
/**
* Generic attribute callback. Will parse the given callback array, w/o any standard callback.
*
* @param element XML element
* @param builder current bean definition builder
* @param callbacks array of callbacks (can be null/empty)
*/
public static void parseAttributes(Element element, BeanDefinitionBuilder builder, AttributeCallback[] callbacks) {
NamedNodeMap attributes = element.getAttributes();
for (int x = 0; x < attributes.getLength(); x++) {
Attr attr = (Attr) attributes.item(x);
boolean shouldContinue = true;
if (!ObjectUtils.isEmpty(callbacks))
for (int i = 0; i < callbacks.length && shouldContinue; i++) {
AttributeCallback callback = callbacks[i];
shouldContinue = callback.process(element, attr, builder);
}
}
}
示例12: loadAttribute
import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
public static Map<String, String> loadAttribute(Element e) {
Map<String, String> map = new HashMap<String, String>();
NamedNodeMap attributes = e.getAttributes();
for(int x=0,n=attributes.getLength();x<n;x++){
Node node = attributes.item(x);
if (node instanceof Attr) {
Attr attr = (Attr) node;
map.put(attr.getName(), attr.getNodeValue());
}
}
return map;
}
示例13: getNamespaceForPrefix
import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
/**
* Given a prefix and a Context Node, get the corresponding namespace.
* Warning: This will not work correctly if namespaceContext
* is an attribute node.
* @param prefix Prefix to resolve.
* @param namespaceContext Node from which to start searching for a
* xmlns attribute that binds a prefix to a namespace.
* @return Namespace that prefix resolves to, or null if prefix
* is not bound.
*/
public String getNamespaceForPrefix(String prefix,
org.w3c.dom.Node namespaceContext) {
Node parent = namespaceContext;
String namespace = null;
if (prefix.equals("xml")) {
namespace = S_XMLNAMESPACEURI;
} else {
int type;
while ((null != parent) && (null == namespace)
&& (((type = parent.getNodeType()) == Node.ELEMENT_NODE)
|| (type == Node.ENTITY_REFERENCE_NODE))) {
if (type == Node.ELEMENT_NODE) {
NamedNodeMap nnm = parent.getAttributes();
for (int i = 0; i < nnm.getLength(); i++) {
Node attr = nnm.item(i);
String aname = attr.getNodeName();
boolean isPrefix = aname.startsWith("xmlns:");
if (isPrefix || aname.equals("xmlns")) {
int index = aname.indexOf(':');
String p =isPrefix ?aname.substring(index + 1) :"";
if (p.equals(prefix)) {
namespace = attr.getNodeValue();
break;
}
}
}
}
parent = parent.getParentNode();
}
}
return namespace;
}
示例14: getPreviousSibling
import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
public Node getPreviousSibling() {
if (parent == null) {
return null;
}
NamedNodeMap attrs = ((Element)parent.getNode()).getAttributes();
if (index > 0) {
return attrs.item(index - 1);
} else {
return null;
}
}
示例15: sortAttributes
import org.w3c.dom.NamedNodeMap; //导入方法依赖的package包/类
/**
* Returns a sorted list of attributes.
*
* @param attrs
* the attrs
* @return the attr[]
*/
protected Attr[] sortAttributes(NamedNodeMap attrs) {
int len = (attrs != null) ? attrs.getLength() : 0;
Attr array[] = new Attr[len];
for (int i = 0; i < len; i++) {
array[i] = (Attr) attrs.item(i);
}
for (int i = 0; i < len - 1; i++) {
String name = array[i].getNodeName();
int index = i;
for (int j = i + 1; j < len; j++) {
String curName = array[j].getNodeName();
if (curName.compareTo(name) < 0) {
name = curName;
index = j;
}
}
if (index != i) {
Attr temp = array[i];
array[i] = array[index];
array[index] = temp;
}
}
return array;
}