xmlns声明分解了多个元素,“全局”范围

时间:2010-11-07 21:25:40

标签: xml xml-namespaces

我想将xmlns声明分成多行。我在教科书中看过它,但是当我尝试复制它时,[shell-tools] [1]给出了下面第二个例子的错误:

/ var / tmp / FOO758cqr:11:解析器错误:标记簿行2中的数据过早结束     

如何更改此内容:

<?xml version="1.0"?>
<!-- initially, the default namespace is "books" -->
<book xmlns="urn:loc.gov:books" xmlns:isbn="urn:ISBN:0-395-36341-6">
  <title>Cheaper by the Dozen</title>
  <isbn:number>1568491379</isbn:number>
  <notes>
    <!-- make HTML the default namespace for some commentary -->
    <p xmlns="http://www.w3.org/1999/xhtml">
          This is a <i>funny</i> book!
      </p>
  </notes>
</book>

到此:

<?xml version="1.0"?>
    <book xmlns="urn:loc.gov:books">
    <book xmlns:isbn="urn:ISBN:0-395-36341-6">
      <title>Cheaper by the Dozen</title>
      <isbn:number>1568491379</isbn:number>
      <notes>
           <p>
              This is a <i>funny</i> book!
          </p>
      </notes>
    </book>

(以上来自scoping@w3

如果有意义的话,我想让两个命名空间的范围成为所有书籍。

感谢,

Thufir

(阅读[codenotes] [3] pg 35)

2 个答案:

答案 0 :(得分:2)

你想:

<book 
    xmlns="urn:loc.gov:books" 
    xmlns:isbn="urn:ISBN:0-395-36341-6">

将属性保留在单个<book>节点中。请注意,您不能有两个根节点,因此在上面的示例中,两个<book>节点不可接受。

答案 1 :(得分:2)

第二个例子不是格式良好的XML(其中一个<book>标签未关闭),这就是错误发生的原因。

您可能想要的是:

<?xml version="1.0"?>
<!-- initially, the default namespace is "books" -->
<book xmlns="urn:loc.gov:books" 
      xmlns:isbn="urn:ISBN:0-395-36341-6">
  <title>Cheaper by the Dozen</title>
  <isbn:number>1568491379</isbn:number>
  <notes>
    <!-- make HTML the default namespace for some commentary -->
    <p xmlns="http://www.w3.org/1999/xhtml">
          This is a <i>funny</i> book!
      </p>
  </notes>
</book>
相关问题