Jaxb vs Jaxp (#14242)

This commit is contained in:
Kingsley✨ 2023-06-27 13:08:52 +00:00 committed by GitHub
parent e3058691b2
commit 0ec89aee72
3 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,9 @@
package com.baeldung.jaxb.jaxpvsjaxb.jaxb;
import jakarta.xml.bind.annotation.XmlElement;
public class Department {
@XmlElement
private String id;
}

View File

@ -0,0 +1,8 @@
package com.baeldung.jaxb.jaxpvsjaxb.jaxb;
import jakarta.xml.bind.annotation.XmlElement;
public class Employee {
@XmlElement
private String id;
}

View File

@ -0,0 +1,18 @@
package com.baeldung.jaxb.jaxpvsjaxb.jaxp;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
public class JaxpExample {
public static void main(String[] args) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse("input.xml");
} catch (Exception e) {
e.printStackTrace();
}
}
}