Я создаю веб-сервис и проект приложения . Сервис хранит данные в локальном XML-файле, содержащем bookInfo. Веб-сервис имеет метод для просмотра всех booksInfo, хранящихся в этом XML-файле. Поэтому для чтения XML я использую JAXB и отправляю его в POJO
немаршалинг
AllItems items = null;
try {
JAXBContext jaxbContext = JAXBContext.newInstance(AllItems.class);
Unmarshaller unMarshaller = jaxbContext.createUnmarshaller();
FileReader fileReader = new FileReader(new File("items.xml"));
items = (AllItems) unMarshaller.unmarshal(fileReader);
//items here is an object of the supposed to be the root element
Ранжирование
После этого я упорядочил это в StringWrite со следующим кодом:
StringWriter stringWriter = new StringWriter();
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(items, stringWriter);
}
catch (JAXBException | FileNotFoundException e) {
e.getMessage();
}
Когда я смотрю вывод на консоли , все выглядит довольно . Если я просматриваю вывод, используя адрес конечной точки в веб-браузере, он все равно выглядит красиво.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<allItems>
<items>
<saleInfo>
<country>AU</country>
<saleability>FOR_SALE</saleability>
</saleInfo>
<status>back order</status>
<volumeInfo>
<authors>Liz Ellis</authors>
<industryIdentifiers>
<identifier>9781760780364</identifier>
<type>ISBN_13</type>
</industryIdentifiers>
<industryIdentifiers>
<identifier>1760780367</identifier>
<type>ISBN_10</type>
</industryIdentifiers>
<publishedDate>2018-04-24</publishedDate>
<publisher>Macmillan Publishers Aus.</publisher>
<title>If At First You Don't Conceive</title>
</volumeInfo>
</items>
Но проблема запускается, когда я использую POSTMAN или пытаюсь просмотреть его с помощью консоли веб-сервера .
Неверный вывод как заставить приложение получать "<" вместо & alt; "</strong>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<allItems>
<items>
<saleInfo>
<country>AU</country>
<saleability>FOR_SALE</saleability>
</saleInfo>
<status>back order</status>
<volumeInfo>
<authors>Liz Ellis</authors>
<industryIdentifiers>
<identifier>9781760780364</identifier>
<type>ISBN_13</type>
</industryIdentifiers>
<industryIdentifiers>
<identifier>1760780367</identifier>
<type>ISBN_10</type>
</industryIdentifiers>
<publishedDate>2018-04-24</publishedDate>
<publisher>Macmillan Publishers Aus.</publisher>
<title>If At First You Don't Conceive</title>
</volumeInfo>
</items>
</allItems>