可视化 XML 树结构 [英] Visualize XML tree structure

查看:30
本文介绍了可视化 XML 树结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个 XML 文件,它们具有相似的结构,但有一些我不能忽视的差异.它们都是 TEI 文档.

I have several XML files which have a similar structure but with some differences that I cannot overlook. They are all TEI documents.

我正在寻找一种方法来概述主要结构.

以下面的文字为例:

<text xmlns="http://www.tei-c.org/ns/1.0" xml:id="d1">
<body xml:id="d2">
<div1 type="book" xml:id="d3">
<head>Songs of Innocence</head>
<pb n="4"/>
<div2 type="poem" xml:id="d4">
<head>Introduction</head>
<lg type="stanza">
<l>Piping down the valleys wild, </l>
<l>Piping songs of pleasant glee, </l>
<l>On a cloud I saw a child, </l>
<l>And he laughing said to me: </l>
</lg>

我想抑制相同类型的节点和所有重复结构:

I would like to suppress the nodes of the same type and all the repeating structures:

<body xml:id="d2">
<div1 type="book" xml:id="d3">
<head>Songs of Innocence</head>
<pb n="4"/>
<div2 type="poem" xml:id="d4">
<head>Introduction</head>
<lg type="stanza">
<l>...</l>
</lg>
<lg>...</lg>

所以,基本上我想将 XML 文档简化为其最基本的结构.通过这种方式,我可以弄清楚如何使用 XSLT 正确转换它们.

So, basically I want to reduce the XML document to its most basic structure. In this way I can figure out how to properly convert them using XSLT.

推荐答案

Using perl XML::DT, (apt-get install libxml-dt-perl 如果没有安装),命令 mkxmltype file.xml 返回对xml 结构.示例

Using perl XML::DT, (apt-get install libxml-dt-perl if not installed), the command mkxmltype file.xml returns a compact description of the xml structure. Example

$ mkxmltype -lines=1000  a.xml 

# text ...Fri Feb 26 17:56:24 2016
text    =>  body * xml:id
body    =>  div1 * xml:id
div1    =>  tup(div2, pb, head) * type * xml:id
div2    =>  tup(head, lg) * type * xml:id
pb  =>  empty * n
head    =>  text
lg  =>  seq(l) * type
l   =>  text

这篇关于可视化 XML 树结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆