我认为这将是一个简单的xml加载和循环,但出于某种原因,我无法从Excel XML电子表格中读取任何内容。
Excel电子表格的内容似乎是标准化输出,如下所示:
<?mso-application progid="Excel.Sheet"?>
<Workbook
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:my-scripts">
<DocumentProperties
xmlns="urn:schemas-microsoft-com:office:office">...
</DocumentProperties>
<OfficeDocumentSettings
xmlns="urn:schemas-microsoft-com:office:office">...
</OfficeDocumentSettings>
<ExcelWorkbook
xmlns="urn:schemas-microsoft-com:office:excel">...
</ExcelWorkbook>
<Styles>...</Styles>
<Worksheet ss:Name="Sheet1" ss:Protected="1">
<Names>
<NamedRange ss:Name="Print_Titles" ss:RefersTo="=Sheet1!C2,Sheet1!R7"/>
</Names>
<Table ss:ExpandedColumnCount="34" ss:ExpandedRowCount="32" x:FullColumns="1" x:FullRows="1" ss:DefaultRowHeight="13.2">
<Column ss:Hidden="1" ss:Width="175.2"/>
<Column ss:Width="250.20000000000002"/>
<Column ss:Width="60" ss:Span="31"/>
<Row ss:AutoFitHeight="0" ss:Height="150" ss:StyleID="s67">...</Row>
<Row ss:Height="15">
<Cell ss:StyleID="s69">
<Data ss:Type="String">W89231</Data>
</Cell>
<Cell ss:StyleID="s70">
<Data ss:Type="String">Tom Brown</Data>
<NamedCell ss:Name="Print_Titles"/>
</Cell>
<Cell ss:StyleID="s69">
<Data ss:Type="String">1E+</Data>
</Cell>
<Cell ss:StyleID="s69">
<Data ss:Type="String">1m</Data>
</Cell>
等等
读过byTagName并不是最好的方法,我首先尝试了以下单节点代码:
strFilename = "1B.xml"
Set oXMLDoc = Server.CreateObject("MSXML2.DOMDocument.6.0")
oXMLDoc.async = False
oXMLDoc.Load (Server.MapPath(strFilename))
Set NodeList = oXMLDoc.documentElement.selectNodes("Workbook/Worksheet")
For Each Node In NodeList
Response.Write Node.selectSingleNode("row/cell/data/text()")
Next
但绝对没有任何反应。
所以我回到了经过试验和信任的byTagName并尝试了以下内容:
strFilename = "1B.xml"
Set oXMLDoc = Server.CreateObject("MSXML2.DOMDocument.6.0")
oXMLDoc.async = False
oXMLDoc.Load (Server.MapPath(strFilename))
Set oRows = oXMLDoc.documentElement.getElementsByTagName("Row")
Response.Write oRows.length
oRows.length反馈为零
即使它是标准的Excel XML电子表格格式,我也似乎无法进入DOM。
如果有人可以解释我如何阅读行并提取必要的数据值,我真的很感激。
此致
汤姆
答案 0 :(得分:2)
管理以发现它完全与名称空间有关。
添加以下行:
String key;
String value2;
String value3;
while(!toVisit.isEmpty()) {
key = someQueue.poll()
value2 = getTitle(key)
value3 = getSize(value2)
jedis.hmset(key, value2Map)
jedis.hmset(key, value3Map)
...
然后我可以在xml中引用标签,如下所示:
Set oXMLDoc = Server.CreateObject("MSXML2.DOMDocument.6.0")
oXMLDoc.setProperty "SelectionLanguage", "XPath"
oXMLDoc.setProperty "SelectionNamespaces", "xmlns:myns='urn:schemas-microsoft-com:office:spreadsheet' xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns:ss='urn:schemas-microsoft-com:office:spreadsheet' xmlns:html='http://www.w3.org/TR/REC-html40' xmlns:msxsl='urn:schemas-microsoft-com:xslt' xmlns:user='urn:my-scripts'"
然后可以开始XML解析! :0)
此致
汤姆