Here you can find the source of readAttributeWithPrefix(Node node, String attributePrefix, String defaultValue)
attributePrefix
.
Parameter | Description |
---|---|
node | node to look for attributes. |
attributePrefix | attribute prefix. |
defaultValue | default returned value. |
public static String readAttributeWithPrefix(Node node, String attributePrefix, String defaultValue)
//package com.java2s; /*//w ww.ja va 2 s. com * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { /** * Reads the value of the first <i>attribute</i> which name matches with the specified <code>attributePrefix</code>. * Returns the <code>defaultValue</code> if not found. * * @param node node to look for attributes. * @param attributePrefix attribute prefix. * @param defaultValue default returned value. * @return the value found or default. */ public static String readAttributeWithPrefix(Node node, String attributePrefix, String defaultValue) { final NamedNodeMap attributes = node.getAttributes(); if (null == attributes) { return defaultValue; } Node attribute; for (int a = 0; a < attributes.getLength(); a++) { attribute = attributes.item(a); if (attribute.getNodeName().startsWith(attributePrefix)) { return attribute.getNodeValue(); } } return defaultValue; } }