Use XML, XPATH to extract info from content.xml

Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
Post Reply
ms777
Volunteer
Posts: 177
Joined: Mon Oct 08, 2007 1:33 am

Use XML, XPATH to extract info from content.xml

Post by ms777 »

Hi,

bitmaps stored in OO document can be extracted by unzipping the document. Their path is an internally given name.
To find out which image belongs to which item in the document the below code snippet lists all images with their name and the path in the zip

Good luck,

ms777

Code: Select all

Sub ListStoredImages
	oDoc = ThisComponent
	
'create an XML document from the content.xml
	oDomBuilder = createUnoService("com.sun.star.xml.dom.DocumentBuilder")
	oDom = oDomBuilder.parse(oDoc.DocumentStorage.getByName("content.xml").Inputstream)
	
'create an XPATH to search for image nodes, which are direct childs of a frame node
	oXPath = createUnoService("com.sun.star.xml.xpath.XPathAPI")
	oNL = oXPath.selectNodeList(oDom, "//*[name()='draw:frame']/*[name()='draw:image']" )
	
	for k=0 to oNL.length-1
		oItem = oNL.item(k)
		sHref = oItem.getAttribute("href")
		sName = oItem.ParentNode.getAttribute("name")
		print sName + ": " + sHref
		
'if you want to extract the image data ...
'		oPic = oDoc.DocumentStorage.getByName("Pictures").getByName(Replace(sHref, "Pictures/", ""))
'		oPic has an InputStream, where you can read the data from
'	    xray oPic

	next k

End Sub
Post Reply