📄 xmlelement.java
字号:
* * <dl><dt><b>Postconditions:</b></dt><dd> * <ul><li><code>result != null</code> * </ul></dd></dl> * * @see nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double) * setDoubleAttribute(String, double) * @see nanoxml.XMLElement#setIntAttribute(java.lang.String, int) * setIntAttribute(String, int) * @see nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) * setAttribute(String, Object) * @see nanoxml.XMLElement#removeAttribute(java.lang.String) * removeAttribute(String) * @see nanoxml.XMLElement#getAttribute(java.lang.String) * getAttribute(String) * @see nanoxml.XMLElement#getAttribute(java.lang.String, java.lang.Object) * getAttribute(String, String) * @see nanoxml.XMLElement#getAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getAttribute(String, Hashtable, String, boolean) * @see nanoxml.XMLElement#getStringAttribute(java.lang.String) * getStringAttribute(String) * @see nanoxml.XMLElement#getStringAttribute(java.lang.String, * java.lang.String) * getStringAttribute(String, String) * @see nanoxml.XMLElement#getStringAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getStringAttribute(String, Hashtable, String, boolean) * @see nanoxml.XMLElement#getIntAttribute(java.lang.String) * getIntAttribute(String) * @see nanoxml.XMLElement#getIntAttribute(java.lang.String, int) * getIntAttribute(String, int) * @see nanoxml.XMLElement#getIntAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getIntAttribute(String, Hashtable, String, boolean) * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String) * getDoubleAttribute(String) * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String, double) * getDoubleAttribute(String, double) * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getDoubleAttribute(String, Hashtable, String, boolean) * @see nanoxml.XMLElement#getBooleanAttribute(java.lang.String, * java.lang.String, * java.lang.String, boolean) * getBooleanAttribute(String, String, String, boolean) */ public Enumeration enumerateAttributeNames() { return this.attributes.keys(); } /** * Enumerates the attribute names. * * @deprecated Use {@link #enumerateAttributeNames() * enumerateAttributeNames} instead. */ public Enumeration enumeratePropertyNames() { return this.enumerateAttributeNames(); } /** * Enumerates the child elements. * * <dl><dt><b>Postconditions:</b></dt><dd> * <ul><li><code>result != null</code> * </ul></dd></dl> * * @see nanoxml.XMLElement#addChild(nanoxml.XMLElement) * addChild(XMLElement) * @see nanoxml.XMLElement#countChildren() * @see nanoxml.XMLElement#getChildren() * @see nanoxml.XMLElement#removeChild(nanoxml.XMLElement) * removeChild(XMLElement) */ public Enumeration enumerateChildren() { return this.children.elements(); } /** * Returns the child elements as a Vector. It is safe to modify this * Vector. * * <dl><dt><b>Postconditions:</b></dt><dd> * <ul><li><code>result != null</code> * </ul></dd></dl> * * @see nanoxml.XMLElement#addChild(nanoxml.XMLElement) * addChild(XMLElement) * @see nanoxml.XMLElement#countChildren() * @see nanoxml.XMLElement#enumerateChildren() * @see nanoxml.XMLElement#removeChild(nanoxml.XMLElement) * removeChild(XMLElement) */ public Vector getChildren() { try { return (Vector) this.children.clone(); } catch (Exception e) { // this never happens, however, some Java compilers are so // braindead that they require this exception clause return null; } } /** * Returns the PCDATA content of the object. If there is no such content, * <CODE>null</CODE> is returned. * * @deprecated Use {@link #getContent() getContent} instead. */ public String getContents() { return this.getContent(); } /** * Returns the PCDATA content of the object. If there is no such content, * <CODE>null</CODE> is returned. * * @see nanoxml.XMLElement#setContent(java.lang.String) * setContent(String) */ public String getContent() { return this.contents; } /** * Returns the line nr in the source data on which the element is found. * This method returns <code>0</code> there is no associated source data. * * <dl><dt><b>Postconditions:</b></dt><dd> * <ul><li><code>result >= 0</code> * </ul></dd></dl> */ public int getLineNr() { return this.lineNr; } /** * Returns an attribute of the element. * If the attribute doesn't exist, <code>null</code> is returned. * * @param name The name of the attribute. * * </dl><dl><dt><b>Preconditions:</b></dt><dd> * <ul><li><code>name != null</code> * <li><code>name</code> is a valid XML identifier * </ul></dd></dl><dl> * * @see nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) * setAttribute(String, Object) * @see nanoxml.XMLElement#removeAttribute(java.lang.String) * removeAttribute(String) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getAttribute(java.lang.String, java.lang.Object) * getAttribute(String, Object) * @see nanoxml.XMLElement#getAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getAttribute(String, Hashtable, String, boolean) */ public Object getAttribute(String name) { return this.getAttribute(name, null); } /** * Returns an attribute of the element. * If the attribute doesn't exist, <code>defaultValue</code> is returned. * * @param name The name of the attribute. * @param defaultValue Key to use if the attribute is missing. * * </dl><dl><dt><b>Preconditions:</b></dt><dd> * <ul><li><code>name != null</code> * <li><code>name</code> is a valid XML identifier * </ul></dd></dl><dl> * * @see nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) * setAttribute(String, Object) * @see nanoxml.XMLElement#removeAttribute(java.lang.String) * removeAttribute(String) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getAttribute(java.lang.String) * getAttribute(String) * @see nanoxml.XMLElement#getAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getAttribute(String, Hashtable, String, boolean) */ public Object getAttribute(String name, Object defaultValue) { if (this.ignoreCase) { name = name.toUpperCase(); } Object value = this.attributes.get(name); if (value == null) { value = defaultValue; } return value; } /** * Returns an attribute by looking up a key in a hashtable. * If the attribute doesn't exist, the value corresponding to defaultKey * is returned. * <P> * As an example, if valueSet contains the mapping <code>"one" => * "1"</code> * and the element contains the attribute <code>attr="one"</code>, then * <code>getAttribute("attr", mapping, defaultKey, false)</code> returns * <code>"1"</code>. * * @param name * The name of the attribute. * @param valueSet * Hashtable mapping keys to values. * @param defaultKey * Key to use if the attribute is missing. * @param allowLiterals * <code>true</code> if literals are valid. * * </dl><dl><dt><b>Preconditions:</b></dt><dd> * <ul><li><code>name != null</code> * <li><code>name</code> is a valid XML identifier * <li><code>valueSet</code> != null * <li>the keys of <code>valueSet</code> are strings * </ul></dd></dl><dl> * * @see nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) * setAttribute(String, Object) * @see nanoxml.XMLElement#removeAttribute(java.lang.String) * removeAttribute(String) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getAttribute(java.lang.String) * getAttribute(String) * @see nanoxml.XMLElement#getAttribute(java.lang.String, java.lang.Object) * getAttribute(String, Object) */ public Object getAttribute(String name, Hashtable valueSet, String defaultKey, boolean allowLiterals) { if (this.ignoreCase) { name = name.toUpperCase(); } Object key = this.attributes.get(name); Object result; if (key == null) { key = defaultKey; } result = valueSet.get(key); if (result == null) { if (allowLiterals) { result = key; } else { throw this.invalidValue(name, (String) key); } } return result; } /** * Returns an attribute of the element. * If the attribute doesn't exist, <code>null</code> is returned. * * @param name The name of the attribute. * * </dl><dl><dt><b>Preconditions:</b></dt><dd> * <ul><li><code>name != null</code> * <li><code>name</code> is a valid XML identifier * </ul></dd></dl><dl> * * @see nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) * setAttribute(String, Object) * @see nanoxml.XMLElement#removeAttribute(java.lang.String) * removeAttribute(String) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getStringAttribute(java.lang.String, * java.lang.String) * getStringAttribute(String, String) * @see nanoxml.XMLElement#getStringAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getStringAttribute(String, Hashtable, String, boolean) */ public String getStringAttribute(String name) { return this.getStringAttribute(name, null); } /** * Returns an attribute of the element. * If the attribute doesn't exist, <code>defaultValue</code> is returned. * * @param name The name of the attribute. * @param defaultValue Key to use if the attribute is missing. * * </dl><dl><dt><b>Preconditions:</b></dt><dd> * <ul><li><code>name != null</code> * <li><code>name</code> is a valid XML identifier * </ul></dd></dl><dl> * * @see nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) * setAttribute(String, Object) * @see nanoxml.XMLElement#removeAttribute(java.lang.String) * removeAttribute(String) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getStringAttribute(java.lang.String) * getStringAttribute(String) * @see nanoxml.XMLElement#getStringAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getStringAttribute(String, Hashtable, String, boolean) */ public String getStringAttribute(String name, String defaultValue) { return (String) this.getAttribute(name, defaultValue); } /** * Returns an attribute by looking up a key in a hashtable. * If the attribute doesn't exist, the value corresponding to defaultKey * is returned. * <P> * As an example, if valueSet contains the mapping <code>"one" => * "1"</code> * and the element contains the attribute <code>attr="one"</code>, then * <code>getAttribute("attr", mapping, defaultKey, false)</code> returns * <code>"1"</code>. * * @param name * The name of the attribute. * @param valueSet * Hashtable mapping keys to values. * @param defaultKey * Key to use if the attribute is missing. * @param allowLiterals * <code>true</code> if literals are valid. * * </dl><dl><dt><b>Preconditions:</b></dt><dd> * <ul><li><code>name != null</code> * <li><code>name</code> is a valid XML identifier * <li><code>valueSet</code> != null * <li>the keys of <code>valueSet</code> are strings * <li>the values of <code>valueSet</code> are strings * </ul></dd></dl><dl> * * @see nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -