Package org.planit.io.xml.util
Interface XmlUtils
-
public interface XmlUtils
Utility methods for parsing XML data- Author:
- gman6028
-
-
Field Summary
Fields Modifier and Type Field Description static Logger
LOGGER
the loggerstatic String
PATH_TO_XSD_FILE
-
Method Summary
Static Methods Modifier and Type Method Description static Object
generateObjectFromXml(Class<?> clazz, String xmlFileLocation)
Generates a Java object populated with the data from an XML input file.static void
generateXmlFileFromObject(Object object, Class<?> clazz, String xmlFileLocation)
Creates an XML output file populated with data from an Objectstatic org.opengis.geometry.DirectPosition
getDirectPositionFromPointType(PlanitGeoUtils planitGeoUtils, net.opengis.gml.PointType pointType)
Create GML position from generated PointType objectstatic void
validateXml(String xmlFileLocation, String schemaFileLocation)
Method to validate an XML input file against an XSD schema using Java XML Validator
-
-
-
Field Detail
-
PATH_TO_XSD_FILE
static final String PATH_TO_XSD_FILE
- See Also:
- Constant Field Values
-
LOGGER
static final Logger LOGGER
the logger
-
-
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
- utilspointType
- 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 fileschemaFileLocation
- 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 populatedxmlFileLocation
- 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 fileclazz
- Class of the object containing the dataxmlFileLocation
- 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
-
-