【发布时间】:2020-10-05 05:44:29
【问题描述】:
我在这个论坛上搜索了类似的问题,但遗憾的是,所有答案都对我没有帮助,MSDN 文档也没有。
我创建了一个 TETML XML 文件,它是 PDF 文件的摘录。 正如标题所示,我想选择一个节点。 最后,我想直接进入“Pages”节点,方便以后浏览。 我的尝试都没有成功。 即使我尝试简单地移动到 Root 元素,我也没有成功:
See Debugging in Visual Studio showing code and result
代码如下:
XmlDocument doc = new XmlDocument();
doc.LoadXml(FileRelatedOperations.ReadAllTextOfFile(filename, true, null));
XmlNamespaceManager nsMgr = new XmlNamespaceManager(doc.NameTable);
nsMgr.AddNamespace("t", "http://www.pdflib.com/XML/TET5/TET-5.0.xsd");
// No success with any of them:
doc.SelectSingleNode("TET");
doc.SelectSingleNode("/TET");
doc.SelectSingleNode("//TET");
doc.SelectSingleNode("t:TET", nsMgr);
doc.SelectSingleNode("/t:TET", nsMgr);
doc.SelectSingleNode("//t:TET", nsMgr);
doc.DocumentElement.SelectSingleNode("t:TET", nsMgr);
doc.DocumentElement.SelectSingleNode("/t:TET", nsMgr);
doc.DocumentElement.SelectSingleNode("//t:TET", nsMgr);
可能是什么原因? 我尝试了使用/不使用 NamespaceManager。
这是原始 XML 的缩写:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created by the PDFlib Text and Image Extraction Toolkit TET (www.pdflib.com) -->
<TET xmlns="http://www.pdflib.com/XML/TET5/TET-5.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.pdflib.com/XML/TET5/TET-5.0
http://www.pdflib.com/XML/TET5/TET-5.0.xsd"
version="5.1">
<Creation platform="Win32" tetVersion="5.1" date="2020-06-15T10:54:14+02:00" />
<Document filename="C:\Temp\AnyPdfFile.pdf" pageCount="8" filesize="379366" linearized="false" pdfVersion="1.4" destination="D0">
<DocInfo>
<Author>Doxis4</Author>
<CreationDate>2020-02-03T10:45:02+01:00</CreationDate>
<Creator>Doxis4 Java API 7.4.2-r202829 (PDFDevice, ITextInterface)</Creator>
<ModDate>2020-02-03T10:45:02+01:00</ModDate>
<Producer>iText 2.1.7 by 1T3XT</Producer>
<Title>Doxis4 Dokument</Title>
</DocInfo>
<Options>tetml={filename={C:\Temp\AnyPdfFile.pdf.xml}}</Options>
<Action type="GoTo" trigger="open"/>
<Pages>
<Page number="1" width="595.00" height="842.00">
<Options>layouthint={header=true} contentanalysis={bidilevel=ltr punctuationbreaks=false} docstyle=papers structureanalysis={list=true} layoutanalysis={layoutdetect=2 layoutrowhint={full separation=preservecolumns}} layouteffort=high granularity=word</Options>
<Content granularity="word" dehyphenation="false" dropcap="false" font="false" geometry="false" shadow="false" sub="false" sup="false">
<Para>
<A id="A0" type="start"/>
<Box llx="40.00" lly="768.10" urx="315.40" ury="777.10">
<Word>
<Text>SomeTextHere</Text>
<Box llx="40.00" lly="768.10" urx="115.60" ury="777.10"/>
</Word>
</Box>
</Para>
</Content>
</Page>
</Pages>
</Document>
</TET>
提前谢谢你:-)!
【问题讨论】:
-
在以下位置找到架构:pdflib.com/XML/TET5/TET-5.0.xsd 我使用 xsd.exe 生成 c# 类,但您的 xml 不适用于架构。是否有更新的模式 5.1?你的xml有效吗?