Interface XmlUtils


  • public interface XmlUtils
    Utility methods for parsing XML data
    Author:
    gman6028
    • Method Detail

      • getDirectPositionFromPointType

        static org.opengis.geometry.DirectPosition getDirectPositionFromPointType​(PlanitGeoUtils planitGeoUtils,
                                                                                  net.opengis.gml.PointType pointType)
                                                                           throws PlanItException
        Create GML position from generated PointType object
        Parameters:
        planitGeoUtils - utils
        pointType - PointType object storing the location, read in from an XML input file
        Returns:
        DirectPosition object storing the location
        Throws:
        PlanItException - thrown if there is an error during processing
      • validateXml

        static void validateXml​(String xmlFileLocation,
                                String schemaFileLocation)
                         throws Exception
        Method to validate an XML input file against an XSD schema using Java XML Validator
        Parameters:
        xmlFileLocation - location of the XML input file
        schemaFileLocation - location of the XSD schema file to validate the XML against
        Throws:
        Exception - thrown if the input file fails the validation
      • generateObjectFromXml

        static Object generateObjectFromXml​(Class<?> clazz,
                                            String xmlFileLocation)
                                     throws Exception
        Generates a Java object populated with the data from an XML input file. This method creates a JAXB Unmarshaller object which it uses to populate the Java class. The output object will be of a generated class, created from the same XSD file which is used to validate the input XML file.
        Parameters:
        clazz - Class of the object to be populated
        xmlFileLocation - location of the input XML file
        Returns:
        an instance of the output class, populated with the data from the XML file.
        Throws:
        Exception - thrown if the XML file is invalid or cannot be opened
      • generateXmlFileFromObject

        static void generateXmlFileFromObject​(Object object,
                                              Class<?> clazz,
                                              String xmlFileLocation)
                                       throws Exception
        Creates an XML output file populated with data from an Object
        Parameters:
        object - input object containing the data to be written to the XML file
        clazz - Class of the object containing the data
        xmlFileLocation - location of the output XML file
        Throws:
        Exception - thrown if the object is not of the correct class, or the output file cannot be opened