Class DefaultXmlFileBuilder

    • Constructor Detail

      • DefaultXmlFileBuilder

        public DefaultXmlFileBuilder​(FileHandler fileHandler)
        creates the instance, which will use the specified @{link FileHandler fileHandler} to read or write the xml file.
        Parameters:
        fileHandler - used for file i/o.
      • DefaultXmlFileBuilder

        public DefaultXmlFileBuilder​(FileHandler fileHandler,
                                     boolean namespaceAware)
        creates the instance, which will use the specified @{link FileHandler fileHandler} to read or write the xml file.
        Parameters:
        fileHandler - used for file i/o.
        namespaceAware - true if builder should be namespace aware.
    • Method Detail

      • setFile

        public void setFile​(String path)
        sets the name of the file we will read and write.
        Specified by:
        setFile in interface XmlFileBuilder
        Parameters:
        path - - where the xml file will be read from or written to.
      • insertElementsUnderXPath

        public void insertElementsUnderXPath​(String elementsToParse,
                                             String xpath)
        this will parse one or more elements from elementToParse and insert them under the xpath. note: elementsToParse may not be well formed, but only in one way. The elements may be missing a parent. Example: the following is acceptable by this method elementsToParse = <child1 /> <child2 /> xpath = //parent In this case, both elements child1 and child2 would be placed under the first match for parent. s
        Specified by:
        insertElementsUnderXPath in interface XmlFileBuilder
        Parameters:
        elementsToParse - String containing one or more elements in textual format
        xpath - where to place the above elements.
      • insertElementUnderXPath

        public void insertElementUnderXPath​(Element elementToInsert,
                                            String xpath)
        This will take element from elementToInsert and insert it under the xpath.
        Specified by:
        insertElementUnderXPath in interface XmlFileBuilder
        Parameters:
        elementToInsert - Element to insert
        xpath - where to place the above element.
      • loadFile

        public Document loadFile()
        load the current xml file into a Document.
        Specified by:
        loadFile in interface XmlFileBuilder
        Returns:
        loaded file, represented as a Document.
      • writeFile

        public void writeFile()
        write the current xml to disk.
        Specified by:
        writeFile in interface XmlFileBuilder
      • setNamespaces

        public void setNamespaces​(Map<String,​String> namespaces)
        assign prefix to namespace mappings used for xpath and other xml operations. Leave alone, or set to null, if you have no namespaces.
        Specified by:
        setNamespaces in interface XmlFileBuilder
        Parameters:
        namespaces - - key is prefix value is url