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
|
Rev | Line | |
---|
[507] | 1 | package gov.hhs.fha.nhinc.repository.util;
|
---|
| 2 |
|
---|
| 3 | import java.io.File;
|
---|
| 4 | import java.io.StringReader;
|
---|
| 5 |
|
---|
| 6 | import javax.xml.parsers.DocumentBuilder;
|
---|
| 7 | import javax.xml.parsers.DocumentBuilderFactory;
|
---|
| 8 |
|
---|
| 9 | import org.w3c.dom.Document;
|
---|
| 10 | import org.xml.sax.InputSource;
|
---|
| 11 |
|
---|
| 12 | /**
|
---|
| 13 | * Utility class for XML processing
|
---|
| 14 | *
|
---|
| 15 | * @author Neil Webb
|
---|
| 16 | */
|
---|
| 17 | public 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.