包含文件问题:命名空间? [英] include file problem: namespaces?

查看:62
本文介绍了包含文件问题:命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用XMLinclude时遇到问题机制,我认为

与命名空间有关。


我有一个有很多重复的XML文件 - 一系列元素

多次出现。我的想法是将这个序列复制到

a单独的文件中,然后使用实体defn来引用那个单独的

文件:


<!ENTITY ThirdPersonAllButTense SYSTEM" 3PersNotTense.xml">


并用& ThirdPersonAllButTense;替换序列。 (没有

特殊原因这个元素序列应该进入一个

* external *文件,但我不知道如何定义一个实体以任何其他方式作为

元素序列。)


但我从xmllint收到错误信息:


元素''FeatureValueSet'':不期望这个元素。

预计是(

{http://lodl.ldc.upenn.edu/ParadigmDefn.xsd } FeatureValueSet)。


如果我理解正确的话,那就是说它希望在元素名称前找到一个

命名空间标识符(和它建议

a URL作为标识符)。此命名空间在调用中被定义为默认的

命名空间。文件,即


< ParadigmDefns xmlns =" http://lodl.ldc.upenn.edu/ParadigmDefn.xsd"

...> ;


包含的文件中没有命名空间定义。 (应该有吗?
怎么样?)


我不确定为什么要这个标识符(如果这确实是这个

错误消息msg意味着)。我对这个外部实体包含

的概念是,它只是复制外部文件的内容

的实体。显然我的概念是错误的,或者我不会得到一个错误的消息,但我不确定为什么。


如果上面的道歉不清楚/使用错误的术语...

解决方案

在文章< 11 ********** ************@i40g2000cwc.googlegroups .com> ;,

< ma ***** @ ldc.upenn.edu>写道:

我有一个有很多重复的XML文件 - 一系列元素
多次出现。我的想法是将这个序列复制到一个单独的文件中,然后使用一个实体defn来引用那个单独的
文件:

<!ENTITY ThirdPersonAllButTense SYSTEM" 3PersNotTense。 xml">

并用& ThirdPersonAllButTense;替换序列。 (这个元素序列应该进入
* external *文件没有特殊原因,但是我不知道如何将实体定义为
序列任何其他方式的元素。)


您可以同样使用内部实体,例如:


<!DOCTYPE foo [

<!ELEMENT foo(bar *)>

<!ELEMENT bar EMPTY>

<!ENTITY lot-of-bars

< bar />

< bar />

< bar />

< bar />

< bar />

">

]>

< foo>

& bars-of-bars;

& bars-of-bars;

< / foo>

元素''FeatureValueSet'':不期望这个元素。
预期是(
{http://lodl.ldc.upenn.edu/ParadigmDefn.xsd } FeatureValueSet)。

如果我理解正确的话,它会说它希望在e前面找到一个
命名空间标识符lement name(并且它建议将URL作为标识符)。此命名空间被定义为调用中的默认名称空间。文件,即

< ParadigmDefns xmlns =" http://lodl.ldc.upenn.edu/ParadigmDefn.xsd"
...>
包含的文件中没有名称空间定义。 (应该有吗?怎么样?)

我不确定为什么它想要这个标识符(如果这确实是这个错误消息的意思)。我对这个外部实体包含
的概念是,它只是将外部文件的内容复制到实体的位置。




那是对的;在命名空间处理之前,我们需要在文本级别工作。

我不知道为什么你会收到这个错误信息。也许你可以发布一个完整的缩减示例,以便其他人可以查看它。


- Richard


>也许你可以发布一个完整的截断

例子,以便其他人可以检查它。




我害怕你会说: - )。该文件是(至少我的b $ b标准)大而复杂,所以我需要一段时间才能将它减少到一个美元。管理。但我会尝试,并感谢

建议!


好的,我把它修剪下来。不幸的是,我在谷歌小组上发帖,所以

我无法附加文件(也许这不是一个禁忌吗?)。所以,这里

如下:


首先,架构,我在一个文件中有BugSchema.xsd:

- ------------- BugSchema.xsd -----------------

<?xml version =" 1.0 ?>

< xsd:schema xmlns:xsd =" http://www.w3.org/2001/XMLSchema"

targetNamespace

=" http://lodl.ldc.upenn.edu/ParadigmDefn.xsd"

xmlns

=" http:// lodl。 ldc.upenn.edu/ParadigmDefn.xsd"

elementFormDefault =" qualified"



< xsd:element name =" ParadigmDefns" ;>

< xsd:complexType>

< xsd:sequence>

< xsd:element ref =" Paradigm" minOccurs =" 1"

maxOccurs =" unbounded" />

< / xsd:sequence>

< / xsd :complexType>

< / xsd:element>


< xsd:element name =" Paradigm">

< xsd:complexType>

< xsd:sequence>

< xsd:element ref =" FeatureValueSet" minOccurs =" 1"

maxOccurs =" unbounded" />

< / xsd:sequence>

< / xsd :complexType>

< / xsd:element>


< xsd:element name =" FeatureValueSet">

< / xsd:element>

< / xsd:schema>

------------------- ----------------------------------------


接下来,要针对该模式验证的文件,Bug.Defn.xml:

------------------ Bug.Defn.xml --------------------

<?xml version =" 1.0" encoding =" ISO-8859-1"?>


<!DOCTYPE ParadigmDefn

[<!ENTITY Inclusion SYSTEM" IncludeBug.xml" ;>]


< ParadigmDefns xmlns

=" http://lodl.ldc.upenn.edu/ParadigmDefn.xsd"

xmlns:xsi

=" http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation =" http ://lodl.ldc.upenn.edu

ParadigmDefn.xsd"



< Paradigm>

<! - - 如果是ff。 ''& Inclusion;''被注释掉,此文件

验证.-->

& Inclusion;

< FeatureValueSet>< / FeatureValueSet>

< / Paradigm>

< / ParadigmDefns>

--------- --------------------------------


最后,包括" file,IncludeBug.xml:

-------------------- IncludeBug.xml ------------- -

< FeatureValueSet>< / FeatureValueSet>

----------------------- ------------------


你会注意到这条线与出现的线相同

紧跟''& Inclusion;'';如果''& Inclusion;''被注释掉,后一行不会导致任何

问题。


错误消息发生(如果包含没有被注释掉)当我运行ff时
。 cmd:


xmllint --noout --noent --schema BugSchema.xsd TestSuite / bug.Defn.xml


具体来说,错误msg是:


元素''FeatureValueSet'':不期望这个元素。预期是

({http://lodl.ldc.upenn.edu/ParadigmDefn.xsd}FeatureValueSet).

TestSuite / bug.Defn.xml无法验证


我在CygWin下运行这个。 xmllint报告使用libxml版本

20622内存文档 (无论那意味着什么 - 听起来像一个

奇数版#,但是......)


感谢您的任何建议!


I''m having a problem using the XML "include" mechanism, which I think
has to do with namespaces.

I have an XML file that has a lot of repetition--a sequence of elements
that appear multiple times. My thought was to copy this sequence into
a separate file, then use an entity defn to refer to that separate
file:

<!ENTITY ThirdPersonAllButTense SYSTEM "3PersNotTense.xml">

and replace the sequences with &ThirdPersonAllButTense;. (There''s no
particular reason this sequence of elements should go into an
*external* file, but I can''t figure out how to define an entity as a
sequence of elements in any other way.)

But I get an error msg from xmllint:

Element ''FeatureValueSet'': This element is not expected.
Expected is (
{http://lodl.ldc.upenn.edu/ParadigmDefn.xsd}FeatureValueSet ).

If I understand this correctly, it''s saying it expected to find a
namespace identifier in front of the element name (and it''s suggesting
a URL as the identifier). This namespace is defined as the default
namespace in the "calling" file, i.e.

<ParadigmDefns xmlns ="http://lodl.ldc.upenn.edu/ParadigmDefn.xsd"
...>

There is no namespace definition in the included file. (Should there
be? How?)

I''m unsure why it wants this identifier (if that is indeed what this
error msg means). My concept of what this external entity inclusion
does, is that it just copies the contents of the external file in place
of the entity. Obviously my concept is wrong, or I wouldn''t be getting
an error msg, but I''m unsure why.

Apologies if the above is unclear/ uses the wrong terminology...

解决方案

In article <11**********************@i40g2000cwc.googlegroups .com>,
<ma*****@ldc.upenn.edu> wrote:

I have an XML file that has a lot of repetition--a sequence of elements
that appear multiple times. My thought was to copy this sequence into
a separate file, then use an entity defn to refer to that separate
file:

<!ENTITY ThirdPersonAllButTense SYSTEM "3PersNotTense.xml">

and replace the sequences with &ThirdPersonAllButTense;. (There''s no
particular reason this sequence of elements should go into an
*external* file, but I can''t figure out how to define an entity as a
sequence of elements in any other way.)
You can use an internal entity equally well, for example:

<!DOCTYPE foo [
<!ELEMENT foo (bar*)>
<!ELEMENT bar EMPTY>
<!ENTITY lots-of-bars "
<bar/>
<bar/>
<bar/>
<bar/>
<bar/>
">
]>
<foo>
&lots-of-bars;
&lots-of-bars;
</foo>
Element ''FeatureValueSet'': This element is not expected.
Expected is (
{http://lodl.ldc.upenn.edu/ParadigmDefn.xsd}FeatureValueSet ).

If I understand this correctly, it''s saying it expected to find a
namespace identifier in front of the element name (and it''s suggesting
a URL as the identifier). This namespace is defined as the default
namespace in the "calling" file, i.e.

<ParadigmDefns xmlns ="http://lodl.ldc.upenn.edu/ParadigmDefn.xsd"
...>

There is no namespace definition in the included file. (Should there
be? How?)

I''m unsure why it wants this identifier (if that is indeed what this
error msg means). My concept of what this external entity inclusion
does, is that it just copies the contents of the external file in place
of the entity.



That''s right; entites work at a textual level before namespace processing.
I don''t know why you''re getting this error message. Perhaps you could
post a complete cut-down example so others can check it.

-- Richard


> Perhaps you could post a complete cut-down

example so others can check it.



I was afraid you were going to say that :-). The file is (by my
standards at least) large and complex, so it will take me awhile to
trim it down to s.t. manageable. But I''ll try, and thanks for the
suggestion!


OK, I trimmed it down. Unfortunately, I''m posting on Google groups, so
I can''t attach files (maybe that''s a no-no here anyway?). So, here
goes:

First, the schema, which I have in a file BugSchema.xsd:
---------------BugSchema.xsd-----------------
<?xml version="1.0"?>
<xsd:schema xmlns:xsd ="http://www.w3.org/2001/XMLSchema"
targetNamespace
="http://lodl.ldc.upenn.edu/ParadigmDefn.xsd"
xmlns
="http://lodl.ldc.upenn.edu/ParadigmDefn.xsd"
elementFormDefault ="qualified"


<xsd:element name="ParadigmDefns">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Paradigm" minOccurs="1"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="Paradigm">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="FeatureValueSet" minOccurs="1"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="FeatureValueSet">
</xsd:element>
</xsd:schema>
-----------------------------------------------------------

Next, the file to be validated against that schema, Bug.Defn.xml:
------------------Bug.Defn.xml--------------------
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE ParadigmDefn
[<!ENTITY Inclusion SYSTEM "IncludeBug.xml">]
<ParadigmDefns xmlns
="http://lodl.ldc.upenn.edu/ParadigmDefn.xsd"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://lodl.ldc.upenn.edu
ParadigmDefn.xsd"


<Paradigm>
<!--If the ff. ''&Inclusion;'' is commented out, this file
validates.-->
&Inclusion;
<FeatureValueSet></FeatureValueSet>
</Paradigm>
</ParadigmDefns>
-----------------------------------------

And finally, the "include" file, IncludeBug.xml:
--------------------IncludeBug.xml---------------
<FeatureValueSet></FeatureValueSet>
-----------------------------------------

You''ll notice that this line is identical to the line that appears
immediately below the ''&Inclusion;''; the latter line does not cause any
problem, if the ''&Inclusion;'' is commented out.

The error msg happens (if the inclusion is not commented out) when I
run the ff. cmd:

xmllint --noout --noent --schema BugSchema.xsd TestSuite/bug.Defn.xml

Specifically, the error msg is:

Element ''FeatureValueSet'': This element is not expected. Expected is
( {http://lodl.ldc.upenn.edu/ParadigmDefn.xsd}FeatureValueSet ).
TestSuite/bug.Defn.xml fails to validate

I''m running this under CygWin. xmllint reports "using libxml version
20622 of the in-memory document" (whatever that means--sounds like an
odd version #, but...)

Thanks for any suggestions!


这篇关于包含文件问题:命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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