views:

137

answers:

4

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>
+6  A: 

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.

eed3si9n
+2  A: 

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.

Brabster
+1  A: 

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.

A: 

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.

peter.murray.rust