我正在使用 Microsoft Excel 中的导出为 XML 功能,我有一个如下 XML 模式定义:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="timeline">
<xs:complexType>
<xs:sequence>
<xs:element name="event" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:all>
<xs:element name="date" type="xs:string" minOccurs="1" />
<xs:element name="title" type="xs:string" minOccurs="1" />
<xs:element name="caption" type="xs:string" minOccurs="0" />
<xs:element name="image" type="xs:anyURI" minOccurs="0" />
</xs:all>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="title" type="xs:string" use="required" />
<xs:attribute name="id" type="xs:string" use="required" />
<xs:attribute name="order" type="xs:int" />
<xs:attribute name="color" type="xs:hexBinary" />
</xs:complexType>
</xs:element>
</xs:schema>
我的表格如下所示:
╔══════╦════════════════════╦════════════════════════╦═══════════╦════════════════╗
║ date ║ title ║ caption ║ reference ║ image ║
╚══════╩════════════════════╩════════════════════════╩═══════════╩════════════════╝
│ 1915 │ Alex's Birthday │ We ate cake. │ rcn_02 │ rcn/rcn_02.png │
│ │ │ │ │ │
│ │ │ He didn't like cake. │ │ │
├──────┼────────────────────┼────────────────────────┼───────────┼────────────────┤
│ 1920 │ Alex starts school │ He didn't like school. │ rcn_03 │ rcn/rcn_03.png │
└──────┴────────────────────┴────────────────────────┴───────────┴────────────────┘
我想要做的是转换多行单元格并将每个部分包装在一个<p>
元素中。因此,当前的输出不是:
<event>
<date>1915</date>
<title>Alex's Birthday</title>
<caption>We ate cake.
He didn't like cake.</caption>
<image>rcn/rcn_02.png</image>
</event>
我想要得到:
<event>
<date>1915</date>
<title>Alex's Birthday</title>
<caption>
<p>We ate cake.</p>
<p>He didn't like cake.</p>
</caption>
<image>rcn/rcn_02.png</image>
</event>
有谁知道如果不手动将标签插入文本(我有数百行)如何实现这一点?
答案1
不幸的是,似乎无法使用 XML 导出器来解析和插入标签。在每个标题单元格周围添加段落标签是一项简单的任务,但在单元格内容中间实际插入段落标签似乎不是 XML 导出功能可以单独完成的任务。但是,假设只有“标题”列需要段落标签,则还有其他适用于您的数据集的解决方法。
利用能够针对回车符和制表符缩进执行搜索和替换操作的文本编辑器(Notepad++、TextWrangler、BBEdit、Microsoft Word),您可以将整个列复制到新的空白文档中。在数据集的开头和结尾放置一个空白回车符。利用以下查找和替换条件,我能够修改您的示例文本以适应:
查找:\n\n
替换:</p><p>
查找:\n
替换:</p>\n<p>
然后,您将获取新格式化的文本并将其粘贴回电子表格中。然后,该列应从如下所示变为:
╦════════════════════════╦ ║ caption ║ ╩════════════════════════╩ │ We ate cake. │ │ │ │ He didn't like cake. │ ┼────────────────────────┼ │ He didn't like school. │ ┴────────────────────────┴
看起来像这样:
╦═══════════════════════════════════════════════════╦ ║ caption ║ ╩═══════════════════════════════════════════════════╩ │ <p>"We ate cake.</p><p>He didn't like cake."</p> │ ┼───────────────────────────────────────────────────┼ │ <p>He didn't like school.</p> │ ┴───────────────────────────────────────────────────┴