以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 XML基础 』  (http://bbs.xml.org.cn/list.asp?boardid=1)
----  如何使用一个XSD文件生成一个空XML文件?  (http://bbs.xml.org.cn/dispbbs.asp?boardid=1&rootid=&id=6312)


--  作者:nmgyao
--  发布时间:3/30/2004 9:34:00 PM

--  如何使用一个XSD文件生成一个空XML文件?
如何使用一个XSD文件生成一个空XML文件?

在XMLSPY中可以将一个XSD文件存为一个空的XML文件,要想实现这个功能该如何?


--  作者:xhaopuj
--  发布时间:4/27/2004 8:16:00 AM

--  
我是在别处看到的转过是:

Q. Can I createe xml document by using DTD or XML Schema?
A: See here.
The answer is yes or no. XML spy or anyone else can make an example from xml schema or dtd easily. I also made 4 examples from my trivial DTD on my FAQ here.
This does not mean you can generate XML deterministically from xml schema or dtd. If you make your algorithm a lot more complicated by using (direct) graph theory, you even can decide the root element. However, it is still non-deterministic.

That is the nature of the problem, nobody can make it deterministic, unless you define your schema in a strict deterministic way, and you restrict your root element, and ... In that case, your xml schema becomes useless and nothing, but a more complicated way to describe your xml. Then why we need the XML schema?


  Q. Can I used a arbitrary defined DTD to generate all possible XML templates?
A: See original discussion here.
The answer is NO unless it is an extreme trivial case. See the really trivial DTD bellow. We already have 4 possible "templates". Here we assume templates is the right word here.  I use one line for each XML file for easy listing. For a little less trivial DTD, it is easy to imagine that all the combination and permutation will cause an exponential explosion. I do not think you want the result, let alone having the space to store the result or writing an application to use that result.
Trivial DTD file
<!ELEMENT person (name,age,sex)>    
<!ELEMENT name (#PCDATA)>    
<!ELEMENT age (#PCDATA)>    
<!ELEMENT sex (#PCDATA)>
Four possible XML "templates"
<name>some_name</name>
<age>some_number</age>
<sex>one_of_the_two</sex>
<person><name>some_name</name><age>some_number</age><sex>one_of_the_two</sex></person>

If you do not believe all four are valid against the DTD, try to validate them by yourself . Here is a related discussion on XML Schema, take a look!


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
62.500ms