"Klaus Jensen" <spamm
...@burninhell.com> wrote in message
news:uZJgzpMjGHA.4504@TK2MSFTNGP05.phx.gbl...
Allow me to answer my own question. :)
I did manage to get the xml in the file using a hack, and then I had access
to the xml-metadata.
It is certainly NOT very pretty code, but it will give another developer
facing a similar challenge something to work with. :)
Public Class ImageMetaData
Public CaptionWriter As String
Public AuthorsPosition As String
Public Credit As String
Public Source As String
Public Category As String
Public Colormode As String
Public ICCProfile As String
Public DateCreated As String
Public Urgency As String
Public Instructions As String
Public Headline As String
Public Description As String
Public Sub New(ByVal filename As String)
Dim xmpXmlDoc As String
xmpXmlDoc = GetXmpXmlDocFromImage(filename)
LoadDoc(xmpXmlDoc)
End Sub
Private Sub LoadDoc(ByVal xmpXmlDoc As String)
Dim xr As New Xml.XmlDocument
Dim nl As Xml.XmlNodeList
Try
xr.LoadXml(xmpXmlDoc)
Catch ex As Exception
Throw New ApplicationException("An error occured while loading XML metadata
from image. The error was: " & ex.Message)
End Try
Try
xr.LoadXml(xmpXmlDoc)
nl = xr.GetElementsByTagName("dc:description")
Me.Description = nl.Item(0).ChildNodes(0).InnerText()
nl = xr.GetElementsByTagName("photoshop:CaptionWriter")
Me.CaptionWriter = nl.Item(0).InnerText()
nl = xr.GetElementsByTagName("photoshop:AuthorsPosition")
Me.AuthorsPosition = nl.Item(0).InnerText()
nl = xr.GetElementsByTagName("photoshop:Credit")
Me.Credit = nl.Item(0).InnerText()
nl = xr.GetElementsByTagName("photoshop:Source")
Me.Source = nl.Item(0).InnerText()
nl = xr.GetElementsByTagName("photoshop:Category")
Me.Category = nl.Item(0).InnerText()
nl = xr.GetElementsByTagName("photoshop:ColorMode")
Me.Colormode = nl.Item(0).InnerText()
nl = xr.GetElementsByTagName("photoshop:ICCProfile")
Me.ICCProfile = nl.Item(0).InnerText()
nl = xr.GetElementsByTagName("photoshop:DateCreated")
Me.DateCreated = nl.Item(0).InnerText()
nl = xr.GetElementsByTagName("photoshop:Urgency")
Me.Urgency = nl.Item(0).InnerText()
nl = xr.GetElementsByTagName("photoshop:Instructions")
Me.Instructions = nl.Item(0).InnerText()
nl = xr.GetElementsByTagName("photoshop:Headline")
Me.Headline = nl.Item(0).InnerText()
Catch ex As Exception
Throw New ApplicationException("Error occured while readning meta-data from
image. The error was: " & ex.Message)
Finally
nl = Nothing
xr = Nothing
End Try
End Sub
Public Overrides Function Tostring() As String
Dim output
output += "CaptionWriter: " & Me.CaptionWriter & vbCrLf
output += "AuthorsPosition: " & Me.AuthorsPosition & vbCrLf
output += "Credit: " & Me.Credit & vbCrLf
output += "Source: " & Me.Source & vbCrLf
output += "Category: " & Me.Category & vbCrLf
output += "Colormode: " & Me.Colormode & vbCrLf
output += "ICCProfile: " & Me.ICCProfile & vbCrLf
output += "DateCreated: " & Me.DateCreated & vbCrLf
output += "Urgency: " & Me.Urgency & vbCrLf
output += "Instructions: " & Me.Instructions & vbCrLf
output += "Headline: " & Me.Headline & vbCrLf
output += "Description: " & Me.Description & vbCrLf
Return output
End Function
Public Shared Function GetXmpXmlDocFromImage(ByVal filename As String) As
String
Dim contents As String
Dim xmlPart As String
Dim beginCapture As String = "<x:xmpmeta"
Dim endCapture As String = "</x:xmpmeta>"
Dim beginPos, endPos As Integer
Dim sr As New System.IO.StreamReader(filename)
contents = sr.ReadToEnd
Debug.Write(contents.Length & " chars" & vbCrLf)
sr.Close()
sr = Nothing
beginPos = InStr(contents, beginCapture, CompareMethod.Text) - 1
endPos = InStr(contents, endCapture, CompareMethod.Text)
Debug.Write("xml found at pos: " & beginPos.ToString & " - " &
endPos.ToString)
xmlPart = contents.Substring(beginPos, (endPos - beginPos) +
endCapture.Length)
Debug.Write("Xml len: " & xmlPart.Length.ToString)
Return xmlPart
End Function
End Class