根据 dtd 更改 xml 的标签
我正在处理这个xml,
<?xml version="1.0"?>
<globalcoverage>
<carrier>
<Data>CONTINENT</Data>
<Data>COUNTY</Data>
<Data>OPERATOR</Data>
<Data>FREQUENCY</Data>
<Data>SIGNATURE</Data>
<Data>GSM</Data>
<Data>GPRS</Data>
<Data>3G</Data>
<Data>PAYMENT</Data>
<Data>SMS</Data>
<Data>ZONE</Data>
<Data>STATUS</Data>
</carrier>
<carrier>
<Data>AFRICA</Data>
<Data>ZAMBIA</Data>
<Data>MTN Zambia</Data>
<Data>GSM 900</Data>
<Data>2006-08-14</Data>
<Data>X</Data>
<Data>X</Data>
<Data>X</Data>
<Data>X</Data>
<Data>X</Data>
<Data>NA</Data>
<Data>0</Data>
</carrier>
...
它有很多记录,我想更改标签,但不想一一进行。有没有办法使用这个 dtd 用氧气来做到这一点?
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT coverturamundial (item+) >
<!ELEMENT item (continent, county, operator, frequency, signature, gsm, gprs, _3g, payment, sms, zone, status) >
<!ELEMENT continent (#PCDATA) >
<!ELEMENT county (#PCDATA) >
<!ELEMENT operator (#PCDATA) >
<!ELEMENT frequency (#PCDATA) >
<!ELEMENT signature (#PCDATA) >
<!ELEMENT gsm (#PCDATA) >
<!ELEMENT gprs (#PCDATA)>
<!ELEMENT _3g (#PCDATA) >
<!ELEMENT payment (#PCDATA) >
<!ELEMENT sms (#PCDATA) >
<!ELEMENT zone (#PCDATA) >
<!ELEMENT status (#PCDATA)>
事实上,数据是从一个xls中获取的。感谢您的帮助。
I'm working with this xml
<?xml version="1.0"?>
<globalcoverage>
<carrier>
<Data>CONTINENT</Data>
<Data>COUNTY</Data>
<Data>OPERATOR</Data>
<Data>FREQUENCY</Data>
<Data>SIGNATURE</Data>
<Data>GSM</Data>
<Data>GPRS</Data>
<Data>3G</Data>
<Data>PAYMENT</Data>
<Data>SMS</Data>
<Data>ZONE</Data>
<Data>STATUS</Data>
</carrier>
<carrier>
<Data>AFRICA</Data>
<Data>ZAMBIA</Data>
<Data>MTN Zambia</Data>
<Data>GSM 900</Data>
<Data>2006-08-14</Data>
<Data>X</Data>
<Data>X</Data>
<Data>X</Data>
<Data>X</Data>
<Data>X</Data>
<Data>NA</Data>
<Data>0</Data>
</carrier>
...
It has a lot more records, I want to change the tags, but don't want to do it one by one. There is a way to do it with oxygen using this dtd?
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT coverturamundial (item+) >
<!ELEMENT item (continent, county, operator, frequency, signature, gsm, gprs, _3g, payment, sms, zone, status) >
<!ELEMENT continent (#PCDATA) >
<!ELEMENT county (#PCDATA) >
<!ELEMENT operator (#PCDATA) >
<!ELEMENT frequency (#PCDATA) >
<!ELEMENT signature (#PCDATA) >
<!ELEMENT gsm (#PCDATA) >
<!ELEMENT gprs (#PCDATA)>
<!ELEMENT _3g (#PCDATA) >
<!ELEMENT payment (#PCDATA) >
<!ELEMENT sms (#PCDATA) >
<!ELEMENT zone (#PCDATA) >
<!ELEMENT status (#PCDATA)>
In fact, the data was taken from a xls. Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为在 oXygen 中有一种自动化的方法可以做到这一点。不过,您可以进行简单的 XSLT 转换。看起来总是有 12 个
Data
元素与 DTD 中item
中的 12 个元素相对应。如果这是真的,您可以根据Data
元素的位置进行转换。这是一个示例样式表(注意:我输出带有系统标识符的 DOCTYPE,以便轻松验证 oXygen 中的输出;您可以删除/更改它):
这是使用示例输入的输出(修改以使其格式良好):
如果您不想为
data
元素执行单独的xsl:template
,您可以执行以下操作:希望这样有帮助。
I don't think that there is an automated way to do this in oXygen. You could do a simple XSLT transform though. It looks like there are always 12
Data
elements that correspond to the 12 elements initem
in the DTD. If this is true, you can base the conversion ofData
elements on their position.Here's a sample stylesheet (NOTE: I'm outputting a DOCTYPE with a system identifier to easily validate the output in oXygen; you can remove/change this):
Here's what the output would be using your sample input (modified to make it well formed):
If you don't want to do individual
xsl:template
's for thedata
elements, you can do something like:Hope this helps.