List of usage examples for com.itextpdf.text.xml.xmp XmpReader XmpReader
public XmpReader(byte[] bytes) throws SAXException, IOException
From source file:org.crossref.pdfmark.XmpUtils.java
License:Open Source License
/** * Parse out all the XmpSchema from a blob of XMP data. *//* w ww .j a v a2 s . co m*/ public static XmpSchema[] parseSchemata(byte[] xmpData) throws XmpException { Document doc = null; try { XmpReader reader = new XmpReader(xmpData); byte[] xmlData = reader.serializeDoc(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.parse(new ByteArrayInputStream(xmlData)); } catch (IOException e) { throw new XmpException(e); } catch (SAXException e) { throw new XmpException(e); } catch (ParserConfigurationException e) { throw new XmpException(e); } NodeList descriptionNodes = doc.getElementsByTagName("rdf:Description"); Map<String, XmpSchema> schemata = new HashMap<String, XmpSchema>(); for (int i = 0; i < descriptionNodes.getLength(); i++) { Element description = (Element) descriptionNodes.item(i); NodeList children = description.getChildNodes(); for (int j = 0; j < children.getLength(); j++) { Node n = children.item(j); if (n instanceof Element) { parseRdfElement(schemata, (Element) n); } } } return schemata.values().toArray(new XmpSchema[0]); }