.net 是否存在用于从XPS文档中提取信息的对象模型?
我已经设法从XPS文档中检索文本并按要求使用它(),但是我想知道是否还有一种与对象相关的模型(与使用.net 是否存在用于从XPS文档中提取信息的对象模型?,.net,vb.net,xps,.net,Vb.net,Xps,我已经设法从XPS文档中检索文本并按要求使用它(),但是我想知道是否还有一种与对象相关的模型(与使用XmlReader)可以使用,该模型可以自动将所有元素放入对象集合中,您可以在代码中循环等等 这是一个人为的例子,但类似于这里的pesudo代码: 'open the xps document Dim xpsDoc As New XpsDocument(pathToTestXps, System.IO.FileAccess.Read) 'load the fixed doc
XmlReader
)可以使用,该模型可以自动将所有元素放入对象集合中,您可以在代码中循环等等
这是一个人为的例子,但类似于这里的pesudo代码:
'open the xps document
Dim xpsDoc As New XpsDocument(pathToTestXps, System.IO.FileAccess.Read)
'load the fixed document squences
Dim fixedDocSeqReader As IXpsFixedDocumentSequenceReader = xpsDoc.FixedDocumentSequenceReader
'the content will go here
Dim sbContent As New System.Text.StringBuilder()
'loops the fixed focuments
For Each docReader As IXpsFixedDocumentReader In fixedDocSeqReader.FixedDocuments
'loop the fixed pages
For Each fixedPageReader As IXpsFixedPageReader In docReader.FixedPages
'BEGIN PSEUDO CODE
Dim content as IXpsContentCollection = fixedPageReader.Contents
For Each contentItem as IXpsContentItem In Contents
Select Case contentItem.Type
Case IXpsContentItem.ContentType.Canvas 'Group
'loop content items, check their type, do stuff
Case IXpsContentItem.ContentType.Glyph 'Text
Dim str As String = DirectCast(contentItem, Glyph).UniCodeString
'do something with the string
Case IXpsContentItem.ContentType.Path 'Shape
'get the shape properties etc
Case Else
Throw New ApplicationException("XPS Content Type Not Expected:" & contentItem.Type.ToString)
End Select
Next
'END PSEUDO CODE
Next
Next
如果没有这样的模型,那么使用XMLReader最简单的方法是什么?是否有一个很好的XML元素和属性参考
就上下文而言,目前我只是在做这件事来代替上面的伪代码:
'get the xml for the fixed pages
Dim pageContentReader As System.Xml.XmlReader = fixedPageReader.XmlReader
While pageContentReader.Read()
'if it is a canvas, it's a new line or some other stuff
If pageContentReader.Name = XmlElementCanvas Then
'other stuff won't have attibutes
If pageContentReader.HasAttributes Then
'remove the last char as it will be an excess comma
If sbContent.Length > 0 Then
sbContent.Length = sbContent.Length - 1
sbContent.AppendLine()
End If
End If
End If
'if it is a glyph, it's the text we want
If pageContentReader.Name = XmlElementGlyphs Then
'unsure, but it was in the example code, so we'll keep it
If pageContentReader.HasAttributes Then
'unicode string attribute has the text we want
If pageContentReader.GetAttribute(XmlAttribUnicodeString) IsNot Nothing Then
'add the text and a comma
sbContent.Append(pageContentReader.GetAttribute(XmlAttribUnicodeString))
sbContent.Append(",")
End If
End If
End If
End While
我也希望有。但是根据文件,不,不好意思,我也这么想。。。我有一份报告需要搜集数据。。。你知道关于如何做到这一点的任何好的文档吗?但是如果你已经收到了文本,你还需要什么(期望)。我真的不知道,我只是想知道是否有什么。。。我的项目的任务是导入报表中包含的数据,因此我们需要对提取的文本应用大量的业务逻辑,以了解其含义,这真是一场噩梦,因为有大量嵌套表和上下文相关数据。iFilter在XPS Essentials包中