Package diva.util.xml

Class XmlDocument


  • public class XmlDocument
    extends java.lang.Object
    An XMLDocument is an in-memory representation of an XML document. It contains an XML element as its root, and other information relevant to the document as a whole, such as its URL, its DTD, and so on. The document can be parsed from or written out to its URL or File, or to some other arbitrary Writer. Documents do not parse themselves, but are passed to an XmlReader.

    See the package summary for a brief description of how to use this class.

    Version:
    $Id$
    Author:
    Steve Neuendorffer, John Reekie
    • Constructor Summary

      Constructors 
      Constructor Description
      XmlDocument()
      Create an XML document with no idea of where it exists.
      XmlDocument​(java.io.File file)
      Create an XML document located in the given file.
      XmlDocument​(java.net.URL url)
      Create an XML document with the given URL.
      XmlDocument​(java.net.URL url, java.lang.String dtdPublicID)
      Create an XML document with the given URL and the DTD system ID.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getDTD()
      Get the DTD of this document.
      java.lang.String getDTDPublicID()
      Get the public ID of the DTD of this document.
      java.lang.String getDTDSystemID()
      Get the system ID of the DTD of this document.
      java.io.File getFile()
      Get the file corresponding to this document.
      XmlElement getRoot()
      Get the root element of this document.
      java.net.URL getURL()
      Get the URL of this document.
      void setDocType​(java.lang.String dt)
      Set the type of this document.
      void setDTD​(java.lang.String dtd)
      Set the DTD of this document.
      void setDTDPublicID​(java.lang.String id)
      Set the DTD of this document by its public ID.
      void setDTDSystemID​(java.lang.String id)
      Set the DTD of this document by its public ID.
      void setFile​(java.io.File file)
      Set the file that this document corresponds to.
      void setRoot​(XmlElement root)
      Set the root element of this document.
      void setURL​(java.net.URL url)
      Set the URL of this document.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • XmlDocument

        public XmlDocument()
        Create an XML document with no idea of where it exists.
      • XmlDocument

        public XmlDocument​(java.net.URL url)
        Create an XML document with the given URL.
      • XmlDocument

        public XmlDocument​(java.io.File file)
        Create an XML document located in the given file.
      • XmlDocument

        public XmlDocument​(java.net.URL url,
                           java.lang.String dtdPublicID)
        Create an XML document with the given URL and the DTD system ID.
    • Method Detail

      • getDTD

        public java.lang.String getDTD()
        Get the DTD of this document. If a DTD has most recently been explicitly set with setDTD(), return that. If the document has most recently been parsed, then return the DTD that was used to parse the document. If neither of these has ever been done, return null.
      • getDTDPublicID

        public java.lang.String getDTDPublicID()
        Get the public ID of the DTD of this document. This field can be set explicitly by the setDTDPublicID() method or by parsing the document. Null if it does not have one.
      • getDTDSystemID

        public java.lang.String getDTDSystemID()
        Get the system ID of the DTD of this document. This field can be set explicitly by the setDTDSystemID() method or by parsing the document. Null if it does not have one.
      • getURL

        public java.net.URL getURL()
        Get the URL of this document. This may be null.
      • getFile

        public java.io.File getFile()
        Get the file corresponding to this document. This may be null.
      • getRoot

        public XmlElement getRoot()
        Get the root element of this document. Null if the document has never been parsed or had its root element explicitly set.
      • setDTD

        public void setDTD​(java.lang.String dtd)
        Set the DTD of this document. The DTD is a string that will be printed when the document is printed. If set to null, the DTD will be set to the DTD system and/or public external identifiers.
      • setDocType

        public void setDocType​(java.lang.String dt)
        Set the type of this document.
      • setDTDPublicID

        public void setDTDPublicID​(java.lang.String id)
        Set the DTD of this document by its public ID.
      • setDTDSystemID

        public void setDTDSystemID​(java.lang.String id)
        Set the DTD of this document by its public ID.
      • setRoot

        public void setRoot​(XmlElement root)
        Set the root element of this document. This method replaces any existing XML content in the document.
      • setFile

        public void setFile​(java.io.File file)
        Set the file that this document corresponds to. When this document is printed or parsed, this is where this document will be printed to or parsed from. If the document also has a non-null URL, then the file location will be ignored.
      • setURL

        public void setURL​(java.net.URL url)
        Set the URL of this document. When this document is printed or parsed, this is where this document will be printed to or parsed from. If the document also has a file object, then it will be ignored once the URL has been set non-null.