|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpl.mbdev.xml.XmlTree
public class XmlTree
XML data represented by a tree.
Copyright 2011 Mateusz Bysiek, mb@mbdev.pl, http://mbdev.pl/ Licensed 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.
Constructor Summary | |
---|---|
XmlTree()
Creates an empty XML tree. |
|
XmlTree(java.lang.String xmlStr)
Creates a tree representing a String with XML contents. |
|
XmlTree(Xml o)
Creates a tree representing an object that implements Xml class. |
|
XmlTree(XmlObject o)
Creates a tree that represents an object that is convertable to XML. |
|
XmlTree(XmlTree tree)
Creates a copy of an another XML tree. |
Method Summary | |
---|---|
void |
addAttribute(java.lang.String name,
java.lang.String value)
Adds new attribute to this node. |
void |
addSubNode(XmlTree node)
Adds new sub node at the first free index. |
void |
addSubNode(XmlTree node,
int subscript)
Adds new subnode with the specific subscript. |
static boolean |
checkIfDtdCorrect(java.lang.String dtdUrl)
Checks if a given DTD URL is semantically correct. |
static boolean |
checkIfNameCorrect(java.lang.String name)
Checks if a given node name is semantically correct. |
static java.lang.String |
createDtdUrl(java.lang.String domainAndUri,
java.lang.String name)
Creates DTD URL out of name of the node and web address with the file. |
static XmlTree |
createFromFile(java.lang.String filePath)
Creates new XmlTree from an external file. |
static java.lang.String |
createHeader(java.lang.String dtdUrl,
java.lang.String name)
Creates XML header with XML document version information, encoding, and link to DTD file. |
static java.lang.String |
createName(java.lang.Class<? extends XmlObject> c)
Creates XML node name for a given object. |
static java.lang.String |
createName(Xml o)
Creates XML node name for a given object. |
java.lang.String |
getAttribute(java.lang.String attrName)
Gets the attribute value for attribute with the given name. |
java.lang.String |
getDtdUrl()
Gets DTD URL of this XML tree. |
java.lang.String |
getName()
Returns name of this node. |
XmlTree |
getSubNode(java.lang.String nodeName,
int subscript)
Gets a sub node with a given subscript. |
java.lang.String |
getValue()
Returns value of this node. |
boolean |
hasCorrectName(Xml o)
Checks if this XML node has a name that corresponds to a given class. |
void |
removeAttribute(java.lang.String name)
Removes attribute that has given name. |
void |
saveToFile(java.lang.String filePath)
Saves this tree to some external file. |
void |
setDtdUrl(java.lang.String dtdUrl)
Sets DTD URL to a given value |
void |
setName(java.lang.String name)
Sets name of this node. |
void |
setValue(java.lang.String value)
Sets the value of this node. |
java.lang.String |
toFullString()
returns the contents of this node and sub-nodes, recursively. |
java.lang.String |
toString()
|
java.lang.String |
toXmlString()
Converts this tree to its XML string representation |
boolean |
validate()
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public XmlTree()
public XmlTree(XmlTree tree)
tree
- source to be copiedpublic XmlTree(java.lang.String xmlStr)
xmlStr
- string containing the whole XML filepublic XmlTree(XmlObject o)
o
- object for conversionpublic XmlTree(Xml o)
o
- the objectMethod Detail |
---|
public static java.lang.String createHeader(java.lang.String dtdUrl, java.lang.String name)
dtdUrl
- URL to DTD filename
- name of the root node
public static java.lang.String createDtdUrl(java.lang.String domainAndUri, java.lang.String name)
domainAndUri
- URI should not end with slash, and should begin with http://
name
- name of the file should not have any extension
public static java.lang.String createName(Xml o)
o
- object for which the name will be created
public static java.lang.String createName(java.lang.Class<? extends XmlObject> c)
c
- class for which the name will be created
public static boolean checkIfDtdCorrect(java.lang.String dtdUrl)
dtdUrl
- URL to be checked
public static boolean checkIfNameCorrect(java.lang.String name)
name
- node name to be checked
public static XmlTree createFromFile(java.lang.String filePath) throws java.io.FileNotFoundException, java.io.IOException
filePath
- path to the file
java.io.FileNotFoundException
- if the file was not found
java.io.IOException
- if there was an exception while reading the filepublic void setDtdUrl(java.lang.String dtdUrl)
dtdUrl
- a DTD URLpublic java.lang.String getDtdUrl()
public void setName(java.lang.String name)
name
- public java.lang.String getName()
public void addAttribute(java.lang.String name, java.lang.String value)
name
- name of the attributevalue
- value of the attributepublic void removeAttribute(java.lang.String name)
name
- public java.lang.String getAttribute(java.lang.String attrName)
attrName
- name of the attribute
public void setValue(java.lang.String value)
value
- public java.lang.String getValue()
public void addSubNode(XmlTree node, int subscript)
node
- subscript
- public void addSubNode(XmlTree node)
node
- sub-nodepublic XmlTree getSubNode(java.lang.String nodeName, int subscript)
nodeName
- subscript
-
public boolean hasCorrectName(Xml o)
o
- object convertible to XML
public boolean validate()
public void saveToFile(java.lang.String filePath) throws java.io.IOException
filePath
-
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toXmlString()
public java.lang.String toFullString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |