代码之家  ›  专栏  ›  技术社区  ›  Sindre Sorhus

这是有效的XML吗?

  •  1
  • Sindre Sorhus  · 技术社区  · 16 年前

    我觉得这个XML是无效的,有人能解释一下原因吗?

    我想这是有点关系的点I元素名?

    estate_price.price_suggestion

    XML

     \\ <?xml version="1.0" encoding="UTF-8"?>
    
    <iad>
      <DataTag>
        <element id="0">
          <changed_string>content</changed_string>
          <no_of_bedrooms>content</no_of_bedrooms>
          <published_string>content</published_string>
          <mmo>content</mmo>
          <postcode>content</postcode>
          <utmx>content</utmx>
          <utmy>content</utmy>
          <disposed>content</disposed>
          <property_type>content</property_type>
          <isprivate>content</isprivate>
          <heading>content</heading>
          <published>content</published>
          <estate_price.price_suggestion>content</estate_price.price_suggestion>
          <ownership_type>content</ownership_type>
          <estate_size.useable_area>content</estate_size.useable_area>
          <adid>content</adid>
          <address>content</address>
          <sqmtrprice>content</sqmtrprice>
          <estate_size.primary_room_area>content</estate_size.primary_room_area>
          <location>content</location>
          <changed>content</changed>
          <orgname>content</orgname>
        </element>
        <element id="1">
          <changed_string>content</changed_string>
          <no_of_bedrooms>content</no_of_bedrooms>
          <published_string>content</published_string>
          <mmo>content</mmo>
          <postcode>content</postcode>
          <utmx>content</utmx>
          <utmy>content</utmy>
          <disposed>content</disposed>
          <property_type>content</property_type>
          <isprivate>content</isprivate>
          <heading>content</heading>
          <published>content</published>
          <estate_price.price_suggestion>content</estate_price.price_suggestion>
          <ownership_type>content</ownership_type>
          <estate_size.useable_area>content</estate_size.useable_area>
          <adid>content</adid>
          <address>content</address>
          <sqmtrprice>content</sqmtrprice>
          <estate_size.primary_room_area>content</estate_size.primary_room_area>
          <location>content</location>
          <changed>content</changed>
          <orgname>content</orgname>
        </element>
      </DataTag>
    </iad>
    
    4 回复  |  直到 16 年前
        1
  •  6
  •   Eugene Yokota    16 年前

    好的XML文档有两个级别: well-formed 而且有效。格式良好表示您符合XML标准,有效表示您符合模式。

    Schema是一个规范,说明您正在使用哪个元素,以及在另一个元素中可以包含什么。您可以使用DTD、XSD(W3CSchema)、RELAXNG等来指定模式。

        2
  •  2
  •   brabster    16 年前

    estate_price.price_suggestion作为XML规范所禁止的元素名没有任何内容,但是您的模式可能会对文档内容和结构施加约束,从而不允许将该元素(或任何其他元素)放置在其所在的位置。

        3
  •  1
  •   masklinn masklinn    16 年前

    Dave Markle是正确的,因为您的XML prolog不应该有反斜杠前缀(另外,请注意,它是可选的,因为它只提供默认的prolog值)。

    to the XML spec for start tags 您将看到它包含一个名称,该名称本身由一个NameStartChar和一个NameChar序列组成。NameChar集碰巧包含字符“”,因此 . 在标记中,只要不是第一个字符,名称就完全有效。

        4
  •  0
  •   peter.murray.rust    16 年前

    http://www.xom.nu )

            try {
            new nu.xom.Builder().build(new StringReader(s));
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("OK");
    

    但是,有些XML工具对属性的类型进行假设。id属性可能被假定为id类型。此类型将id值限制为只能以_A-Za-z开头的有效XML名称(而不是“0-9”、““-”或“.”)。因此,尽管XML格式良好,但使用数字作为ID可能不是一个好主意。如前所述,如果您有DTD或模式,则id可能被强制为id类型,这将导致验证失败。

    从你的帖子中不清楚你是否已经遇到了问题——如果是这样,发布错误消息可能会有所帮助。

    推荐文章