Java Code Examples for javax.xml.transform.stream.StreamResult.setSystemId()

The following are Jave code examples for showing how to use setSystemId() of the javax.xml.transform.stream.StreamResult class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: emr-nlp-server   File: XMLUtil.java   View Source Code Vote up 5 votes
/**
 * Save list of record IDs as an XML file.
 * 
 * @param dbName
 * @param itemList
 * @param nodeName
 * @param fn_xml
 * @throws Exception
 */
public static void createXMLDatasetFileFromList(String dbName, String[] itemList,
        String nodeName, String fn_xml) throws Exception {                
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

    // root elements
    Document doc = docBuilder.newDocument();        
    
    Element rootElement = doc.createElement("Dataset");
    doc.appendChild(rootElement);        
    // attributes for root node
    rootElement.setAttribute("type", DATASET_TYPE_COLON);
    rootElement.setAttribute("name", dbName);
    rootElement.setAttribute("databaseroot", "./");
    
    Element ele;
    for(String item : itemList) {
        ele = doc.createElement(nodeName);
        ele.appendChild(doc.createTextNode(item));
        
        rootElement.appendChild(ele);
    }
    
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    DOMSource source = new DOMSource(doc);
    File outputFile = new File(fn_xml);
    StreamResult result = new StreamResult(outputFile);
    // replace %20 by whitespace
    result.setSystemId(result.getSystemId().replaceAll("%20", " "));
    
    transformer.transform(source, result);
}
 
Example 2
Project: OpenJSharp   File: XMLOutputFactoryImpl.java   View Source Code Vote up 5 votes
/** StreamResult object is re-used and the values are set appropriately.
 */
StreamResult toStreamResult(OutputStream os, Writer writer, String systemId){
    StreamResult sr = new StreamResult();
    sr.setOutputStream(os);
    sr.setWriter(writer);
    sr.setSystemId(systemId);
    return sr;
}
 
Example 3
Project: jaffa-framework   File: PrintXmlUtility.java   View Source Code Vote up 5 votes
@Override
public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
    File file = new File(fileName);
    StreamResult result = new StreamResult(file);
    result.setSystemId(file.toURI().toURL().toString());
    return result;
}
 
Example 4
Project: openjdk-jdk10   File: XMLOutputFactoryImpl.java   View Source Code Vote up 5 votes
/** StreamResult object is re-used and the values are set appropriately.
 */
StreamResult toStreamResult(OutputStream os, Writer writer, String systemId){
    StreamResult sr = new StreamResult();
    sr.setOutputStream(os);
    sr.setWriter(writer);
    sr.setSystemId(systemId);
    return sr;
}
 
Example 5
Project: emr-nlp-server   File: XMLUtil.java   View Source Code Vote up 4 votes
/**
 * Save a list of models in XML file
 * 
 * @param sessionIDList
 * @param userIDList
 * @param varIDList
 * @param predictorXMLFolder
 * @param maxSessionID
 * @param maxUserID
 * @param fn_xmlPredictor
 * @return
 * @throws Exception
 */
public static String createXMLPredictor(String[] sessionIDList, String[] userIDList, 
        String[] varIDList, String predictorXMLFolder, String maxSessionID,
        String maxUserID, String fn_xmlPredictor) throws Exception {
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

    // root elements
    Document doc = docBuilder.newDocument();        
    
    Element rootElement = doc.createElement("MLPredictor");
    doc.appendChild(rootElement);        
    // attributes for root node
    rootElement.setAttribute("type", "mlpredictor_colonoscopy_vars");
    rootElement.setAttribute("name", "emr-vis-nlp_colonoscopy_" +
            maxSessionID  + "_" + maxUserID);
    rootElement.setAttribute("modelroot", "./");
    // removed the foldname
    
    Element ele;
    Element vals;
    String varID, userID, sessionID;
    for(int i = 0; i < varIDList.length; i++) {
        varID = varIDList[i];
        userID = userIDList[i];
        sessionID = sessionIDList[i];
        ele = doc.createElement("Attr");
        ele.setAttribute("name", varID);
        ele.setAttribute("type", "variable_categorical");
        ele.setAttribute("fileName", sessionID + "." + userID + "." + varID);
        vals = doc.createElement("Vals");
        vals.appendChild(doc.createTextNode("False True"));
        ele.appendChild(vals);
        
        rootElement.appendChild(ele);
    }
    
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    DOMSource source = new DOMSource(doc);
    File outputFile = new File(fn_xmlPredictor);
    StreamResult result = new StreamResult(outputFile);
    // replace %20 by whitespace
    result.setSystemId(result.getSystemId().replaceAll("%20", " "));
    
    transformer.transform(source, result);
    
    return rootElement.getAttribute("name");
}