source: ccr/trunk/nhin-vista/projects/NHINC/Current/Product/Production/Adapters/General/DocumentRepository/src/gov/hhs/fha/nhinc/repository/util/XmlUtil.java@ 507

Last change on this file since 507 was 507, checked in by George Lilly, 15 years ago

NHIN gateway and adaptor for use on linux with VistA EHR and RPMS

File size: 1.5 KB
Line 
1package gov.hhs.fha.nhinc.repository.util;
2
3import java.io.File;
4import java.io.StringReader;
5
6import javax.xml.parsers.DocumentBuilder;
7import javax.xml.parsers.DocumentBuilderFactory;
8
9import org.w3c.dom.Document;
10import org.xml.sax.InputSource;
11
12/**
13 * Utility class for XML processing
14 *
15 * @author Neil Webb
16 */
17public class XmlUtil
18{
19 public static Document getDocumentFromString(String xmlString)
20 throws Exception
21 {
22 DocumentBuilderFactory oDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
23 try
24 {
25 // Do not load the DTD
26 oDocumentBuilderFactory.setAttribute(
27 "http://apache.org/xml/features/nonvalidating/load-external-dtd",
28 Boolean.FALSE);
29 }
30 catch (IllegalArgumentException e)
31 {
32 }
33 DocumentBuilder oDocumentBuilder = oDocumentBuilderFactory.newDocumentBuilder();
34
35 InputSource inputSource = new InputSource(new StringReader(xmlString));
36 return oDocumentBuilder.parse(inputSource);
37 }
38
39 public static Document getDocumentFromFile(String absolutePath)
40 throws Exception
41 {
42 DocumentBuilderFactory oDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
43 DocumentBuilder oDocumentBuilder = oDocumentBuilderFactory.newDocumentBuilder();
44
45 Document oDocument = null;
46
47 oDocument = oDocumentBuilder.parse(new File(absolutePath));
48
49 return oDocument;
50 }
51
52}
Note: See TracBrowser for help on using the repository browser.