这是有效的 XML 吗?

发布于 2024-08-03 19:05:05 字数 2729 浏览 5 评论 0原文

我感觉这个 XML 无效,有人可以解释一下为什么吗?

我认为元素名称中的点有什么作用?

estate_price.price_suggestion

该 XML 还有其他无效的地方吗?

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>

I have a feeling this XML is not valid, can someone please explain why?

I think it has something todo this the dot i the element name?

estate_price.price_suggestion

Any thing else not valid about this XML?

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

花落人断肠 2024-08-10 19:05:05

好的 XML 文档有两个级别:格式良好和有效。格式正确意味着您遵守 XML 标准,有效意味着您符合模式。

架构是您正在使用哪个元素以及可以在另一个元素中包含哪些元素的规范。您可以使用 DTD、XSD(W3C 架构)、Relax NG 等来指定架构。

There are two levels of good XML document: well-formed and valid. Well-formed means you comply to XML standard and valid means you conform to a schema.

Schema is a specification of which element you are using and what can go inside the other. You could use DTD, XSD (W3C Schema), Relax NG, etc. to specify the schema.

白况 2024-08-10 19:05:05

我们需要有您正在验证的架构来告诉您您的文档是否有效。

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

We would need to have the schema you are validating against to tell you whether your document is valid or not.

There is nothing about estate_price.price_suggestion as an element name that is forbidden by the XML specification, however your schema may well place a constraint over your document content and structure that does not permit that element (or any other element) to be placed where it is.

虚拟世界 2024-08-10 19:05:05

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

至于元素名称中的点,如果您查看开始标记的 XML 规范< /a> 您将看到它包含一个 Name,该 Name 本身由 NameStartChar 和 NameChar 序列组成。 NameChar 集恰好包含字符“.”,因此标记名称中包含 . 是完全有效的,只要它不是第一个字符即可。

Dave Markle is correct in that your XML prolog shouldn't have the backslash prefixes (also, note that it's optional since it's only giving the default prolog values).

As for the dot in element name, if you go to the XML spec for start tags you'll see that it contains a Name which is itself made of a NameStartChar and a sequence of NameChar. The NameChar set happens to contain the character ".", so having a . in a tag name is perfectly valid as long as it's not the first character.

洋洋洒洒 2024-08-10 19:05:05

您的 XML 格式良好,应该可以在任何非验证 XML 解析器中进行解析。例如,我使用了 XOM(来自 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 值限制为有效的 XML 名称,只能以 _A-Za-z 开头(不是“0-9”、“-”或“.”)。因此,尽管您的 XML 格式良好,但使用数字作为 id 可能不是一个好主意。正如已经指出的,如果您有 DTD 或模式,那么 id 可能会被强制为 ID 类型,这会导致验证失败。

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

Your XML is well-formed and should parse in any non-validating XML parser. For example I have used XOM (from http://www.xom.nu)

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

However there are some XML tools which make assumptions about the type of attributes. The id attribute MIGHT be assumed to be of type ID. This type restricts id values to be valid XML names which can only start with _A-Za-z (not '0-9', '-' or '.'). Thus although your XML is well formed it may be a poor idea to use numbers for ids. As already pointed out IF you have a DTD or schema then the id might have been forced to be of type ID which would cause a validation failure.

It's not clear from your post whether you had already had a problem - if so posting the error message might help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文