Parse an XML into Java - MetaData Format

658 views Asked by At

I saw some xml parsing in java but I really don't know how I can apply it to my code.

Here is my xml file:

<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xml:base="https://adomain.com">
   <id>https://sharepoint.mydomain/aFile)</id>
   <category term="SP.File" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

   <title />
   <updated>2015-05-18T07:13:18Z</updated>
   <author>
      Bla Bla<name />
   </author>
   <content type="application/xml">
      <m:properties>
         <d:CheckInComment />
         <d:CheckOutType m:type="Edm.Int32">2</d:CheckOutType>
         <d:ContentTag>{63FD2CFA-D223-405B-86B3-D59B34ECEBBE},3,1</d:ContentTag>
         <d:CustomizedPageStatus m:type="Edm.Int32">0</d:CustomizedPageStatus>
         <d:ETag>"{63FD2CFA-D223-405B-86B3-D59B34ECEBBE},3"</d:ETag>
         <d:Exists m:type="Edm.Boolean">true</d:Exists>
         <d:Length m:type="Edm.Int64">638367</d:Length>
         <d:Level m:type="Edm.Byte">2</d:Level>
         <d:MajorVersion m:type="Edm.Int32">0</d:MajorVersion>
         <d:MinorVersion m:type="Edm.Int32">1</d:MinorVersion>
         <d:Name>aName.pdf</d:Name>
         <d:ServerRelativeUrl>/mydomain.com/afile</d:ServerRelativeUrl>
         <d:TimeCreated m:type="Edm.DateTime">2014-09-03T15:30:22Z</d:TimeCreated>
         <d:TimeLastModified m:type="Edm.DateTime">2014-09-03T15:30:25Z</d:TimeLastModified>
         <d:Title />
         <d:UIVersion m:type="Edm.Int32">1</d:UIVersion>
         <d:UIVersionLabel>0.1</d:UIVersionLabel>
      </m:properties>
   </content>
</entry>

I am trying to get the metadata of a file from SharePoint which is displayed in xml format.

How can I get the data which is inside the content and also the title and the author like this:

Author BlaBla
Title Bla
Type application/xml
TimeLastModified xx/xx/xxxx
2

There are 2 answers

0
Noorus Khan On

You can use Jaxb, now a days it is used for parsing purpose very effectively, Converting XML to JAVA called UnMarshalling http://www.javatpoint.com/jaxb-tutorial

1
Tavo On

The easiest way to parse XML files is the DOM parser. You can find the documentation here and a few tutorials here and here.

Also, a related question in stackoverflow here.