Skip to content

Commit 330c868

Browse files
Ashearapivovarit
authored andcommitted
XML libraries support (eugenp#463)
* dom4j * added more parsers * StaxParser * Jaxb binding * Jaxb binding * Finish article
1 parent a661e0e commit 330c868

20 files changed

Lines changed: 980 additions & 166 deletions

‎xml/pom.xml‎

Lines changed: 112 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,117 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
4-
<groupId>com.baeldung</groupId>
5-
<artifactId>xml</artifactId>
6-
<version>0.1-SNAPSHOT</version>
7-
8-
<name>xml</name>
9-
10-
<dependencies>
11-
<!-- utils -->
12-
13-
<dependency>
14-
<groupId>com.google.guava</groupId>
15-
<artifactId>guava</artifactId>
16-
<version>${guava.version}</version>
17-
</dependency>
18-
19-
<dependency>
20-
<groupId>commons-io</groupId>
21-
<artifactId>commons-io</artifactId>
22-
<version>2.4</version>
23-
</dependency>
24-
25-
<dependency>
26-
<groupId>org.apache.commons</groupId>
27-
<artifactId>commons-collections4</artifactId>
28-
<version>4.0</version>
29-
</dependency>
30-
31-
<dependency>
32-
<groupId>org.apache.commons</groupId>
33-
<artifactId>commons-lang3</artifactId>
34-
<version>${commons-lang3.version}</version>
35-
</dependency>
36-
37-
38-
<!-- test scoped -->
39-
40-
<dependency>
41-
<groupId>junit</groupId>
42-
<artifactId>junit</artifactId>
43-
<version>${junit.version}</version>
44-
<scope>test</scope>
45-
</dependency>
46-
47-
<dependency>
48-
<groupId>org.hamcrest</groupId>
49-
<artifactId>hamcrest-core</artifactId>
50-
<version>${org.hamcrest.version}</version>
51-
<scope>test</scope>
52-
</dependency>
53-
<dependency>
54-
<groupId>org.hamcrest</groupId>
55-
<artifactId>hamcrest-library</artifactId>
56-
<version>${org.hamcrest.version}</version>
57-
<scope>test</scope>
58-
</dependency>
59-
60-
<dependency>
61-
<groupId>org.mockito</groupId>
62-
<artifactId>mockito-core</artifactId>
63-
<version>${mockito.version}</version>
64-
<scope>test</scope>
65-
</dependency>
66-
67-
</dependencies>
68-
69-
<build>
70-
<finalName>xml</finalName>
71-
<resources>
72-
<resource>
73-
<directory>src/main/resources</directory>
74-
<filtering>true</filtering>
75-
</resource>
76-
</resources>
77-
78-
<plugins>
79-
80-
<plugin>
81-
<groupId>org.apache.maven.plugins</groupId>
82-
<artifactId>maven-compiler-plugin</artifactId>
83-
<version>${maven-compiler-plugin.version}</version>
84-
<configuration>
85-
<source>1.8</source>
86-
<target>1.8</target>
87-
</configuration>
88-
</plugin>
89-
90-
<plugin>
91-
<groupId>org.apache.maven.plugins</groupId>
92-
<artifactId>maven-surefire-plugin</artifactId>
93-
<version>${maven-surefire-plugin.version}</version>
94-
</plugin>
95-
96-
</plugins>
97-
98-
</build>
99-
100-
<properties>
101-
<!-- persistence -->
102-
<hibernate.version>4.3.11.Final</hibernate.version>
103-
<mysql-connector-java.version>5.1.38</mysql-connector-java.version>
104-
105-
<!-- marshalling -->
106-
<jackson.version>2.7.2</jackson.version>
107-
108-
<!-- logging -->
109-
<org.slf4j.version>1.7.13</org.slf4j.version>
110-
<logback.version>1.1.3</logback.version>
111-
112-
<!-- various -->
113-
<hibernate-validator.version>5.1.3.Final</hibernate-validator.version>
114-
115-
<!-- util -->
116-
<guava.version>19.0</guava.version>
117-
<commons-lang3.version>3.4</commons-lang3.version>
118-
119-
<!-- testing -->
120-
<org.hamcrest.version>1.3</org.hamcrest.version>
121-
<junit.version>4.12</junit.version>
122-
<mockito.version>1.10.19</mockito.version>
123-
124-
<httpcore.version>4.4.1</httpcore.version>
125-
<httpclient.version>4.5</httpclient.version>
126-
127-
<rest-assured.version>2.9.0</rest-assured.version>
128-
129-
<!-- maven plugins -->
130-
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
131-
<maven-war-plugin.version>2.6</maven-war-plugin.version>
132-
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
133-
<maven-resources-plugin.version>2.7</maven-resources-plugin.version>
134-
<cargo-maven2-plugin.version>1.4.18</cargo-maven2-plugin.version>
135-
136-
</properties>
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.baeldung</groupId>
5+
<artifactId>xml</artifactId>
6+
<version>0.1-SNAPSHOT</version>
7+
8+
<name>xml</name>
9+
10+
<dependencies>
11+
<!-- xml libraries -->
12+
<dependency>
13+
<groupId>dom4j</groupId>
14+
<artifactId>dom4j</artifactId>
15+
<version>1.6.1</version>
16+
</dependency>
17+
<dependency>
18+
<groupId>jaxen</groupId>
19+
<artifactId>jaxen</artifactId>
20+
<version>1.1.6</version>
21+
</dependency>
22+
23+
24+
<dependency>
25+
<groupId>org.jdom</groupId>
26+
<artifactId>jdom2</artifactId>
27+
<version>2.0.6</version>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>xerces</groupId>
32+
<artifactId>xercesImpl</artifactId>
33+
<version>2.9.1</version>
34+
</dependency>
35+
36+
<!-- utils -->
37+
<dependency>
38+
<groupId>commons-io</groupId>
39+
<artifactId>commons-io</artifactId>
40+
<version>2.4</version>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>org.apache.commons</groupId>
45+
<artifactId>commons-collections4</artifactId>
46+
<version>4.0</version>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>org.apache.commons</groupId>
51+
<artifactId>commons-lang3</artifactId>
52+
<version>${commons-lang3.version}</version>
53+
</dependency>
54+
55+
56+
<!-- test scoped -->
57+
58+
<dependency>
59+
<groupId>junit</groupId>
60+
<artifactId>junit</artifactId>
61+
<version>${junit.version}</version>
62+
<scope>test</scope>
63+
</dependency>
64+
65+
</dependencies>
66+
67+
<build>
68+
<finalName>xml</finalName>
69+
<resources>
70+
<resource>
71+
<directory>src/main/resources</directory>
72+
<filtering>true</filtering>
73+
</resource>
74+
</resources>
75+
76+
<plugins>
77+
78+
<plugin>
79+
<groupId>org.apache.maven.plugins</groupId>
80+
<artifactId>maven-compiler-plugin</artifactId>
81+
<version>${maven-compiler-plugin.version}</version>
82+
<configuration>
83+
<source>1.8</source>
84+
<target>1.8</target>
85+
</configuration>
86+
</plugin>
87+
88+
<plugin>
89+
<groupId>org.apache.maven.plugins</groupId>
90+
<artifactId>maven-surefire-plugin</artifactId>
91+
<version>${maven-surefire-plugin.version}</version>
92+
</plugin>
93+
94+
</plugins>
95+
96+
</build>
97+
98+
<properties>
99+
100+
<!-- util -->
101+
<guava.version>19.0</guava.version>
102+
<commons-lang3.version>3.4</commons-lang3.version>
103+
104+
<!-- testing -->
105+
<junit.version>4.12</junit.version>
106+
107+
<!-- maven plugins -->
108+
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
109+
<maven-war-plugin.version>2.6</maven-war-plugin.version>
110+
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
111+
<maven-resources-plugin.version>2.7</maven-resources-plugin.version>
112+
<cargo-maven2-plugin.version>1.4.18</cargo-maven2-plugin.version>
113+
114+
</properties>
137115

138116
</project>
139117

‎xml/src/main/java/com/baeldung/xml/DefaultParser.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public NodeList getFirstLevelNodeList() {
3939

4040
XPath xPath = XPathFactory.newInstance().newXPath();
4141

42-
String expression = "/Tutorials/Tutorial";
42+
String expression = "/tutorials/tutorial";
4343

4444
nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
4545

@@ -60,7 +60,7 @@ public Node getNodeById(String id) {
6060

6161
XPath xPath = XPathFactory.newInstance().newXPath();
6262

63-
String expression = "/Tutorials/Tutorial[@tutId=" + "'" + id + "'" + "]";
63+
String expression = "/tutorials/tutorial[@tutId=" + "'" + id + "'" + "]";
6464

6565
node = (Node) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODE);
6666

@@ -83,7 +83,7 @@ public NodeList getNodeListByTitle(String name) {
8383

8484
XPath xPath = XPathFactory.newInstance().newXPath();
8585

86-
String expression = "//Tutorial[descendant::title[text()=" + "'" + name + "'" + "]]";
86+
String expression = "//tutorial[descendant::title[text()=" + "'" + name + "'" + "]]";
8787

8888
nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
8989

@@ -107,7 +107,7 @@ public NodeList getElementsByDate(String date) {
107107

108108
XPath xPath = XPathFactory.newInstance().newXPath();
109109

110-
String expression = "//Tutorial[number(translate(date, '/', '')) > " + date + "]";
110+
String expression = "//tutorial[number(translate(date, '/', '')) > " + date + "]";
111111

112112
nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
113113

@@ -151,7 +151,7 @@ public String getNamespaceURI(String arg0) {
151151
}
152152
});
153153

154-
String expression = "/bdn:Tutorials/bdn:Tutorial";
154+
String expression = "/bdn:tutorials/bdn:tutorial";
155155

156156
nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
157157

0 commit comments

Comments
 (0)