本文整理汇总了Java中org.w3c.dom.Attr.getNodeValue方法的典型用法代码示例。如果您正苦于以下问题:Java Attr.getNodeValue方法的具体用法?Java Attr.getNodeValue怎么用?Java Attr.getNodeValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.Attr
的用法示例。
在下文中一共展示了Attr.getNodeValue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildDerivationTree
import org.w3c.dom.Attr; //导入方法依赖的package包/类
public static void buildDerivationTree(Element mother, Node derivation){
Element t = derivDoc.createElement("tree");
NamedNodeMap atts = derivation.getAttributes();
for (int i = 0 ; i < atts.getLength() ; i++){
Attr a = (Attr) atts.item(i);
String name = a.getNodeName();
String val = a.getNodeValue();
if (name.equals("id")) {
t.setAttribute("id", val);
} else if (name.equals("op")) {
t.setAttribute("op", val);
} else if (name.equals("op-node")) {
t.setAttribute("node", val);
} // skip the other attributes
}
NodeList childList = derivation.getChildNodes();
for (int i = 0; i < childList.getLength(); i++)
{
Node child = childList.item(i);
if (child instanceof Element)
{
buildDerivationTree(t, child);
}
}
mother.appendChild(t);
}
示例2: buildDerivedTree
import org.w3c.dom.Attr; //导入方法依赖的package包/类
public static void buildDerivedTree(Element mother, Node derived){
Element t = derivDoc.createElement("node");
Element narg = derivDoc.createElement("narg");
t.appendChild(narg);
Element fs= derivDoc.createElement("fs");
narg.appendChild(fs);
NamedNodeMap atts = derived.getAttributes();
for (int i = 0 ; i < atts.getLength() ; i++){
Attr a = (Attr) atts.item(i);
Element f = derivDoc.createElement("f");
String name = a.getNodeName();
f.setAttribute("name", name);
String val = a.getNodeValue();
buildVal(f, val);
fs.appendChild(f);
}
NodeList childList = derived.getChildNodes();
for (int i = 0; i < childList.getLength(); i++)
{
Node child = childList.item(i);
if (child instanceof Element)
{
buildDerivedTree(t, child);
}
}
if (childList.getLength() == 0) {
//lex node
t.setAttribute("type", "lex");
t.setAttribute("value", derived.getNodeName());
} else {
t.setAttribute("type", "std");
}
mother.appendChild(t);
}
示例3: extractFqcns
import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
* Extracts the fully qualified class names from the manifest and uses the
* prefix notation relative to the manifest package. This basically reverses
* the effects of {@link #expandFqcns(Document)}, though of course it may
* also remove prefixes which were inlined in the original documents.
*
* @param doc the document in which to extract the FQCNs.
*/
private void extractFqcns(Document doc) {
// Find the package attribute of the manifest.
String pkg = null;
Element manifest = findFirstElement(doc, "/manifest");
if (manifest != null) {
pkg = manifest.getAttribute("package");
}
if (pkg == null || pkg.length() == 0) {
return;
}
int pkgLength = pkg.length();
for (String elementAttr : sClassAttributes) {
String[] names = elementAttr.split("/");
if (names.length != 2) {
continue;
}
String elemName = names[0];
String attrName = names[1];
NodeList elements = doc.getElementsByTagName(elemName);
for (int i = 0; i < elements.getLength(); i++) {
Node elem = elements.item(i);
if (elem instanceof Element) {
Attr attr = ((Element) elem).getAttributeNodeNS(NS_URI, attrName);
if (attr != null) {
String value = attr.getNodeValue();
// We know it's a shortened FQCN if it starts with a dot
// or does not contain any dot.
if (value != null && value.length() > pkgLength &&
value.startsWith(pkg) && value.charAt(pkgLength) == '.') {
value = value.substring(pkgLength);
attr.setNodeValue(value);
}
}
}
}
}
}
示例4: CipherReferenceImpl
import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
* @param uri
*/
public CipherReferenceImpl(Attr uri) {
referenceURI = uri.getNodeValue();
referenceNode = uri;
}
示例5: handleAttributesSubtree
import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
* Returns the Attr[]s to be output for the given element.
* <br>
* The code of this method is a copy of {@link #handleAttributes(Element,
* NameSpaceSymbTable)},
* whereas it takes into account that subtree-c14n is -- well --
* subtree-based.
* So if the element in question isRoot of c14n, it's parent is not in the
* node set, as well as all other ancestors.
*
* @param element
* @param ns
* @return the Attr[]s to be output
* @throws CanonicalizationException
*/
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
throws CanonicalizationException {
if (!element.hasAttributes() && !firstCall) {
return null;
}
// result will contain the attrs which have to be output
final SortedSet<Attr> result = this.result;
result.clear();
if (element.hasAttributes()) {
NamedNodeMap attrs = element.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr attribute = (Attr) attrs.item(i);
String NUri = attribute.getNamespaceURI();
String NName = attribute.getLocalName();
String NValue = attribute.getValue();
if (!XMLNS_URI.equals(NUri)) {
// It's not a namespace attr node. Add to the result and continue.
result.add(attribute);
} else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) {
// The default mapping for xml must not be output.
Node n = ns.addMappingAndRender(NName, NValue, attribute);
if (n != null) {
// Render the ns definition
result.add((Attr)n);
if (C14nHelper.namespaceIsRelative(attribute)) {
Object exArgs[] = {element.getTagName(), NName, attribute.getNodeValue()};
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs
);
}
}
}
}
}
if (firstCall) {
// It is the first node of the subtree
// Obtain all the namespaces defined in the parents, and added to the output.
ns.getUnrenderedNodes(result);
// output the attributes in the xml namespace.
xmlattrStack.getXmlnsAttr(result);
firstCall = false;
}
return result.iterator();
}
示例6: handleAttributesSubtree
import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
* Returns the Attr[]s to be output for the given element.
* <br>
* The code of this method is a copy of {@link #handleAttributes(Element,
* NameSpaceSymbTable)},
* whereas it takes into account that subtree-c14n is -- well -- subtree-based.
* So if the element in question isRoot of c14n, it's parent is not in the
* node set, as well as all other ancestors.
*
* @param element
* @param ns
* @return the Attr[]s to be output
* @throws CanonicalizationException
*/
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
throws CanonicalizationException {
if (!element.hasAttributes() && !firstCall) {
return null;
}
// result will contain the attrs which have to be output
final SortedSet<Attr> result = this.result;
result.clear();
if (element.hasAttributes()) {
NamedNodeMap attrs = element.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr attribute = (Attr) attrs.item(i);
String NUri = attribute.getNamespaceURI();
String NName = attribute.getLocalName();
String NValue = attribute.getValue();
if (!XMLNS_URI.equals(NUri)) {
//It's not a namespace attr node. Add to the result and continue.
result.add(attribute);
} else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) {
//The default mapping for xml must not be output.
Node n = ns.addMappingAndRender(NName, NValue, attribute);
if (n != null) {
//Render the ns definition
result.add((Attr)n);
if (C14nHelper.namespaceIsRelative(attribute)) {
Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() };
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs
);
}
}
}
}
}
if (firstCall) {
//It is the first node of the subtree
//Obtain all the namespaces defined in the parents, and added to the output.
ns.getUnrenderedNodes(result);
//output the attributes in the xml namespace.
xmlattrStack.getXmlnsAttr(result);
firstCall = false;
}
return result.iterator();
}
示例7: getNamespaceForPrefix
import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
* Given an XML Namespace prefix and a context in which the prefix
* is to be evaluated, return the Namespace Name this prefix was
* bound to. Note that DOM Level 3 is expected to provide a version of
* this which deals with the DOM's "early binding" behavior.
*
* Default handling:
*
* @param prefix String containing namespace prefix to be resolved,
* without the ':' which separates it from the localname when used
* in a Node Name. The empty sting signifies the default namespace
* at this point in the document.
* @param namespaceContext Element which provides context for resolution.
* (We could extend this to work for other nodes by first seeking their
* nearest Element ancestor.)
*
* @return a String containing the Namespace URI which this prefix
* represents in the specified context.
*/
public String getNamespaceForPrefix(String prefix, Element namespaceContext)
{
int type;
Node parent = namespaceContext;
String namespace = null;
if (prefix.equals("xml"))
{
namespace = QName.S_XMLNAMESPACEURI; // Hardcoded, per Namespace spec
}
else if(prefix.equals("xmlns"))
{
// Hardcoded in the DOM spec, expected to be adopted by
// Namespace spec. NOTE: Namespace declarations _must_ use
// the xmlns: prefix; other prefixes declared as belonging
// to this namespace will not be recognized and should
// probably be rejected by parsers as erroneous declarations.
namespace = "http://www.w3.org/2000/xmlns/";
}
else
{
// Attribute name for this prefix's declaration
String declname=(prefix=="")
? "xmlns"
: "xmlns:"+prefix;
// Scan until we run out of Elements or have resolved the namespace
while ((null != parent) && (null == namespace)
&& (((type = parent.getNodeType()) == Node.ELEMENT_NODE)
|| (type == Node.ENTITY_REFERENCE_NODE)))
{
if (type == Node.ELEMENT_NODE)
{
// Look for the appropriate Namespace Declaration attribute,
// either "xmlns:prefix" or (if prefix is "") "xmlns".
// TODO: This does not handle "implicit declarations"
// which may be created when the DOM is edited. DOM Level
// 3 will define how those should be interpreted. But
// this issue won't arise in freshly-parsed DOMs.
// NOTE: declname is set earlier, outside the loop.
Attr attr=((Element)parent).getAttributeNode(declname);
if(attr!=null)
{
namespace = attr.getNodeValue();
break;
}
}
parent = getParentOfNode(parent);
}
}
return namespace;
}
示例8: getAttributeValue
import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
* Returns the value of the given "android:attribute" in the given element.
*
* @param element The non-null element where to extract the attribute.
* @param attrName The local name of the attribute.
* It must use the {@link #NS_URI} but no prefix should be specified here.
* @return The value of the attribute or a non-null empty string if not found.
*/
private String getAttributeValue(Element element, String attrName) {
Attr attr = element.getAttributeNodeNS(NS_URI, attrName);
String value = attr == null ? "" : attr.getNodeValue(); //$NON-NLS-1$
return value;
}