Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97544363
XMLParser.java
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Jan 5, 03:30
Size
1 KB
Mime Type
text/x-java
Expires
Tue, Jan 7, 03:30 (2 d)
Engine
blob
Format
Raw Data
Handle
23335260
Attached To
R3229 Genome Privacy - SHCS App
XMLParser.java
View Options
package
io.serializer.xml
;
import
io.serializer.Parser
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.StringReader
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
org.jdom2.Document
;
import
org.jdom2.JDOMException
;
import
org.jdom2.input.SAXBuilder
;
import
org.jdom2.output.Format
;
import
org.jdom2.output.XMLOutputter
;
import
org.xml.sax.InputSource
;
public
class
XMLParser
extends
Parser
{
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
XMLParser
.
class
.
getName
());
private
SAXBuilder
builder
;
private
XMLOutputter
xmlOutput
;
protected
static
final
String
SEP_INT
=
","
;
protected
static
final
String
SEP_EXT
=
";"
;
public
XMLParser
()
{
builder
=
new
SAXBuilder
();
xmlOutput
=
new
XMLOutputter
();
xmlOutput
.
setFormat
(
Format
.
getCompactFormat
());
// xmlOutput.setFormat(Format.getPrettyFormat());
}
protected
Document
stringToDocument
(
String
src
)
throws
JDOMException
{
InputSource
inputSrc
=
new
InputSource
(
new
StringReader
(
src
));
try
{
return
builder
.
build
(
inputSrc
);
}
catch
(
IOException
e
)
{
LOGGER
.
log
(
Level
.
SEVERE
,
null
,
e
);
}
return
null
;
}
protected
String
documentToString
(
Document
doc
)
throws
IOException
{
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
xmlOutput
.
output
(
doc
,
baos
);
String
res
=
baos
.
toString
();
return
res
;
}
}
Event Timeline
Log In to Comment