Java XML Tutorial - Java Document .setDocumentURI (String documentURI)








Syntax

Document.setDocumentURI(String documentURI) has the following syntax.

void setDocumentURI(String documentURI)

Example

In the following code shows how to use Document.setDocumentURI(String documentURI) method.

import java.io.StringReader;
//w  ww  . j av  a  2 s .c o m
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;

public class Main {
  public static void main(String args[]) throws Exception{
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = builderFactory.newDocumentBuilder();  // Create the parser
    Document xmlDoc = builder.parse(new InputSource(new StringReader(xmlString)));

    xmlDoc.setDocumentURI("http://java2s.com");
    
  }
  static String xmlString ="<?xml version=\"1.0\"?>" +
      "  <address id='asdf'>" +
      "    <buildingnumber> 29 </buildingnumber>" +
      "    <street> South Street</street>" +
      "    <city>Vancouver</city>" +
      "" +
      "    <state>BC</state>" +
      "    <zip>V6V 4U7</zip>" +
      "  </address>";
}