📄 xmlelement.java
字号:
* * @see nanoxml.XMLElement#XMLElement() * @see nanoxml.XMLElement#XMLElement(boolean) * @see nanoxml.XMLElement#XMLElement(java.util.Hashtable) * XMLElement(Hashtable) */ public XMLElement(Hashtable entities, boolean skipLeadingWhitespace) { this(entities, skipLeadingWhitespace, true, true); } /** * Creates and initializes a new XML element. * * @param entities * The entity conversion table. * @param skipLeadingWhitespace * <code>true</code> if leading and trailing whitespace in PCDATA * content has to be removed. * @param ignoreCase * <code>true</code> if the case of element and attribute names have * to be ignored. * * </dl><dl><dt><b>Preconditions:</b></dt><dd> * <ul><li><code>entities != null</code> * </ul></dd></dl> * * <dl><dt><b>Postconditions:</b></dt><dd> * <ul><li>countChildren() => 0 * <li>enumerateChildren() => empty enumeration * <li>enumeratePropertyNames() => empty enumeration * <li>getChildren() => empty vector * <li>getContent() => "" * <li>getLineNr() => 0 * <li>getName() => null * </ul></dd></dl><dl> * * @see nanoxml.XMLElement#XMLElement() * @see nanoxml.XMLElement#XMLElement(boolean) * @see nanoxml.XMLElement#XMLElement(java.util.Hashtable) * XMLElement(Hashtable) * @see nanoxml.XMLElement#XMLElement(java.util.Hashtable,boolean) * XMLElement(Hashtable, boolean) */ public XMLElement(Hashtable entities, boolean skipLeadingWhitespace, boolean ignoreCase) { this(entities, skipLeadingWhitespace, true, ignoreCase); } /** * Creates and initializes a new XML element. * <P> * This constructor should <I>only</I> be called from * {@link #createAnotherElement() createAnotherElement} * to create child elements. * * @param entities * The entity conversion table. * @param skipLeadingWhitespace * <code>true</code> if leading and trailing whitespace in PCDATA * content has to be removed. * @param fillBasicConversionTable * <code>true</code> if the basic entities need to be added to * the entity list. * @param ignoreCase * <code>true</code> if the case of element and attribute names have * to be ignored. * * </dl><dl><dt><b>Preconditions:</b></dt><dd> * <ul><li><code>entities != null</code> * <li>if <code>fillBasicConversionTable == false</code> * then <code>entities</code> contains at least the following * entries: <code>amp</code>, <code>lt</code>, <code>gt</code>, * <code>apos</code> and <code>quot</code> * </ul></dd></dl> * * <dl><dt><b>Postconditions:</b></dt><dd> * <ul><li>countChildren() => 0 * <li>enumerateChildren() => empty enumeration * <li>enumeratePropertyNames() => empty enumeration * <li>getChildren() => empty vector * <li>getContent() => "" * <li>getLineNr() => 0 * <li>getName() => null * </ul></dd></dl><dl> * * @see nanoxml.XMLElement#createAnotherElement() */ protected XMLElement(Hashtable entities, boolean skipLeadingWhitespace, boolean fillBasicConversionTable, boolean ignoreCase) { this.ignoreWhitespace = skipLeadingWhitespace; this.ignoreCase = ignoreCase; this.name = null; this.contents = ""; this.attributes = new Hashtable(); this.children = new Vector(); this.entities = entities; this.lineNr = 0; Enumeration enum = this.entities.keys(); while (enum.hasMoreElements()) { Object key = enum.nextElement(); Object value = this.entities.get(key); if (value instanceof String) { value = ((String) value).toCharArray(); this.entities.put(key, value); } } if (fillBasicConversionTable) { this.entities.put("amp", new char[] { '&' }); this.entities.put("quot", new char[] { '"' }); this.entities.put("apos", new char[] { '\'' }); this.entities.put("lt", new char[] { '<' }); this.entities.put("gt", new char[] { '>' }); } } /** * Adds a child element. * * @param child * The child element to add. * * </dl><dl><dt><b>Preconditions:</b></dt><dd> * <ul><li><code>child != null</code> * <li><code>child.getName() != null</code> * <li><code>child</code> does not have a parent element * </ul></dd></dl> * * <dl><dt><b>Postconditions:</b></dt><dd> * <ul><li>countChildren() => old.countChildren() + 1 * <li>enumerateChildren() => old.enumerateChildren() + child * <li>getChildren() => old.enumerateChildren() + child * </ul></dd></dl><dl> * * @see nanoxml.XMLElement#countChildren() * @see nanoxml.XMLElement#enumerateChildren() * @see nanoxml.XMLElement#getChildren() * @see nanoxml.XMLElement#removeChild(nanoxml.XMLElement) * removeChild(XMLElement) */ public void addChild(XMLElement child) { this.children.addElement(child); } /** * Adds or modifies an attribute. * * @param name * The name of the attribute. * @param value * The value 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 * <li><code>value != null</code> * </ul></dd></dl> * * <dl><dt><b>Postconditions:</b></dt><dd> * <ul><li>enumerateAttributeNames() * => old.enumerateAttributeNames() + name * <li>getAttribute(name) => value * </ul></dd></dl><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#enumerateAttributeNames() * @see nanoxml.XMLElement#getAttribute(java.lang.String) * getAttribute(String) * @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) * @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) */ public void setAttribute(String name, Object value) { if (this.ignoreCase) { name = name.toUpperCase(); } this.attributes.put(name, value.toString()); } /** * Adds or modifies an attribute. * * @param name * The name of the attribute. * @param value * The value of the attribute. * * @deprecated Use {@link #setAttribute(java.lang.String, java.lang.Object) * setAttribute} instead. */ public void addProperty(String name, Object value) { this.setAttribute(name, value); } /** * Adds or modifies an attribute. * * @param name * The name of the attribute. * @param value * The value 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><dt><b>Postconditions:</b></dt><dd> * <ul><li>enumerateAttributeNames() * => old.enumerateAttributeNames() + name * <li>getIntAttribute(name) => value * </ul></dd></dl><dl> * * @see nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double) * setDoubleAttribute(String, double) * @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#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) */ public void setIntAttribute(String name, int value) { if (this.ignoreCase) { name = name.toUpperCase(); } this.attributes.put(name, Integer.toString(value)); } /** * Adds or modifies an attribute. * * @param name * The name of the attribute. * @param value * The value of the attribute. * * @deprecated Use {@link #setIntAttribute(java.lang.String, int) * setIntAttribute} instead. */ public void addProperty(String key, int value) { this.setIntAttribute(key, value); } /** * Adds or modifies an attribute. * * @param name * The name of the attribute. * @param value * The value 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><dt><b>Postconditions:</b></dt><dd> * <ul><li>enumerateAttributeNames() * => old.enumerateAttributeNames() + name * <li>getDoubleAttribute(name) => value * </ul></dd></dl><dl> * * @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#enumerateAttributeNames() * @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) */ public void setDoubleAttribute(String name, double value) { if (this.ignoreCase) { name = name.toUpperCase(); } this.attributes.put(name, Double.toString(value)); } /** * Adds or modifies an attribute. * * @param name * The name of the attribute. * @param value * The value of the attribute. * * @deprecated Use {@link #setDoubleAttribute(java.lang.String, double) * setDoubleAttribute} instead. */ public void addProperty(String name, double value) { this.setDoubleAttribute(name, value); } /** * Returns the number of child elements of the element. * * <dl><dt><b>Postconditions:</b></dt><dd> * <ul><li><code>result >= 0</code> * </ul></dd></dl> * * @see nanoxml.XMLElement#addChild(nanoxml.XMLElement) * addChild(XMLElement) * @see nanoxml.XMLElement#enumerateChildren() * @see nanoxml.XMLElement#getChildren() * @see nanoxml.XMLElement#removeChild(nanoxml.XMLElement) * removeChild(XMLElement) */ public int countChildren() { return this.children.size(); } /** * Enumerates the attribute names.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -