Search Java Code Snippets

  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.

#Java - Code Snippets for '#Xml' - 10 code snippet(s) found

 Sample 1. Rest Web Service ( Post ) using Jersey, XML

public class RestWebServiceJersey {
public String submitEmployeeInfo(Employee employee) {
StatusDto status = insertIntoDb(employee);
return status;

   Like      Feedback     rest  @post  @consumes  @produces  xml  rest web service  jersey

 Sample 2. Usage of org.xml.sax.XMLReader

XMLReader xr = XMLReaderFactory.createXMLReader();
HttpURLConnection connection = openConnection("/listPaths" + path,
"ugi=" + ugi + (recur? "&recursive=yes" : ""));

InputStream resp = connection.getInputStream();
xr.parse(new InputSource(resp));

   Like      Feedback     org.xml.sax.XMLReader

 Sample 3. Usage of javax.xml.transform.Transformer, TransformerFactory

TransformerFactory tFactory = TransformerFactory.newInstance();

Transformer transformer = tFactory.newTransformer(
new StreamSource(styleSheet)

transformer.transform(new StreamSource(xml), new StreamResult(out));

   Like      Feedback     TransformerFactory  Transformer

 Sample 4. Code Sample / Example / Snippet of com.fasterxml.jackson.core.JsonToken

  private void expectScalarField(JsonParser parser, String name)

throws IOException {

expect(parser, JsonToken.FIELD_NAME);

if (!parser.getCurrentName().equals(name)) {

throw new RuntimeException("expected field " + name + ", got "

+ parser.getCurrentName());


final JsonToken t = parser.nextToken();

switch (t) {









throw new RuntimeException("expected scalar field, got " + t);



   Like      Feedback      com.fasterxml.jackson.core.JsonToken

Subscribe to Java News and Posts. Get latest updates and posts on Java from
Enter your email address:
Delivered by FeedBurner
 Sample 5. Code Sample / Example / Snippet of com.fasterxml.jackson.databind.ObjectMapper

  public JsonEnumerator(File file) {

try {

final ObjectMapper mapper = new ObjectMapper();

mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);

mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);

mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);

List<Object> list = mapper.readValue(file, List.class);

enumerator = Linq4j.enumerator(list);

} catch (IOException e) {

throw new RuntimeException(e);



   Like      Feedback      com.fasterxml.jackson.databind.ObjectMapper

 Sample 6. Print Marshaled XML for the Entity object

Employee employee = new Employee()

JAXBContext context = JAXBContext.newInstance(Employee.class);
Marshaller marshaller = context.createMarshaller();
marshaller.marshal(employee, System.out); // prints XML for the object

   Like      Feedback     Marshalling  Marshal Object to XML   Object to XML

 Sample 7. Code Sample / Example / Snippet of org.xml.sax.Attributes

    public InputStream getDeploymentPackage(String id, String version) throws OverloadedException, IOException {

List<ArtifactData> data = m_provider.getBundleData(id, version);

Manifest manifest = new Manifest();

Attributes main = manifest.getMainAttributes();

main.putValue("Manifest-Version", "1.0");

main.putValue("DeploymentPackage-SymbolicName", id);

main.putValue("DeploymentPackage-Version", version);

for (ArtifactData bd : data) {

manifest.getEntries().put(bd.getFilename(), bd.getManifestAttributes(false));


return DeploymentPackageStream.createStreamForThread(m_connectionFactory, manifest, data.iterator(), false);


   Like      Feedback      org.xml.sax.Attributes

 Sample 8. Code Sample / Example / Snippet of org.apache.ace.deployment.provider.repositorybased.BaseRepositoryHandler.XmlDeploymentArtifact

    public void testGatherSingleArtifactOk() throws Exception {

DeploymentArtifactCollector handler = new DeploymentArtifactCollector(TARGET, VERSION1);

m_parser.parse(m_inputStream, handler);

List<XmlDeploymentArtifact>[] artifacts = handler.getArtifacts();

assert artifacts.length == 1 : "Expected a single artifact to be found!";

assert artifacts[0].size() == 1 : "Expected a single artifact to be found!";

XmlDeploymentArtifact artifact1 = artifacts[0].get(0);

assert new URL("file:///bundle1").equals(artifact1.getUrl()) : "Expected 'file:///bundle1' URL to be found!";

assert artifact1.getDirective().size() == 2 : "Expected two directives to be found!";

assert "bundle1".equals(artifact1.getDirective().get(KEY_SYMBOLICNAME)) : "Expected correct symbolic name to be found!";

assert "1.0.0".equals(artifact1.getDirective().get(KEY_VERSION)) : "Expected correct bundle version to be found!";


   Like      Feedback      org.apache.ace.deployment.provider.repositorybased.BaseRepositoryHandler.XmlDeploymentArtifact

 Sample 9. Code Sample / Example / Snippet of javax.xml.parsers.SAXParserFactory

    protected void setUp() throws Exception {

SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();

m_parser = saxParserFactory.newSAXParser();

String xml = generateValidTestXml();

m_inputStream = new ByteArrayInputStream(xml.getBytes());


   Like      Feedback      javax.xml.parsers.SAXParserFactory

Subscribe to Java News and Posts. Get latest updates and posts on Java from
Enter your email address:
Delivered by FeedBurner
 Sample 10. Code Sample / Example / Snippet of javax.xml.parsers.DocumentBuilderFactory

    private Document getDocument(InputStream input) throws IOException {

try {

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder;

builder = factory.newDocumentBuilder();

return builder.parse(input);


catch (ParserConfigurationException e) {

throw new IOException("Error instantiation XML parser:" + e.getMessage());


catch (SAXException e) {

throw new IOException("Error parsing user data:" + e.getMessage());



   Like      Feedback      javax.xml.parsers.DocumentBuilderFactory

Subscribe to Java News and Posts. Get latest updates and posts on Java from
Enter your email address:
Delivered by FeedBurner