SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    Silly XML question

    Hey all,

    I've never actually delved into the world of XML yet, but I have a pretty basic question quickly here. Is it valid XML to have something like this?
    Code:
    <parent>
    	<child>#1</child>
    	<child>#2</child>
    	<parent>
    		<child>#1</child>
    	</parent>
    </parent>
    I want to set up an app that would have to parse some info structured like that out of a file and I figured if I could make the file valid XML then that would just have to be a bonus

    Thanks

  2. #2
    SitePoint Guru asterix's Avatar
    Join Date
    Jun 2003
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it valid?

    Strictly speaking, it is well-formed. To see if it is valid or not depends on the DTD. It could be valid, there is nothing preventing recursive hierarchies in XML.

  3. #3
    SitePoint Zealot basicwebus's Avatar
    Join Date
    Jul 2003
    Location
    Missouri
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    looks like your second parent would be a child element of child#2. As long as it is defined in your schema that way, I think it would work okay.
    After the third time of reading the instructions,
    it finally soaks in to my thick skull.



  4. #4
    grasshoppa Snowbird122's Avatar
    Join Date
    Apr 2001
    Location
    Austin
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, your XML is valid. XML handles parent/child type data very well.
    http://www.echo-consulting.net - Sound Solutions for Online Inspriations.

  5. #5
    SitePoint Guru asterix's Avatar
    Join Date
    Jun 2003
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't say that the XML is valid without having a scehma or DTD, you can only say that it is well formed.

    As I said, the XML *could* be valid, there is nothing inherently wrong with its structure. But without the DTD it is impossible to say.

  6. #6
    grasshoppa Snowbird122's Avatar
    Join Date
    Apr 2001
    Location
    Austin
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You may be right. If no schema or DTD is linked to in the XML, can you assume that the XML is then valid, since it will not cause any parsing errors?
    http://www.echo-consulting.net - Sound Solutions for Online Inspriations.

  7. #7
    SitePoint Guru asterix's Avatar
    Join Date
    Jun 2003
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If there is no schema or DTD you still can not say that the XML is valid, you can only say "well - formed and potentially valid".

    The lack of parse errors means that the parser could read the XML: it was well-formed. Validation errors will only occur if their is an authority to be validated against...

  8. #8
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well formed XML ? Well, yes though IMO you should not have duplicate TAGS in any one level.

    Okay, a DTD would validate this XML if required though if for example, at a later date you want to import your XML data to a database then you are going to have repeatitive data yes...

    ... As you have CHILD more than once on one structure level for example ? Hope this makes sense as I've seen a number of folk hand over an XML document such like you have your data for example, and they've just got it straight back with a wee note to ask they to normalise the document

    Very costly mistake I can assure you

  9. #9
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DJ P@CkMaN
    Code:
    <parent>
    	<child>#1</child>
    	<child>#2</child>
    	<parent>
    		<child>#1</child>
    	</parent>
    </parent>
    Looks like it's well formed, maybe it's potentially valid too, but is it useful and/or the way you should describe that info?

    Isn't <parent> nodes the same type of objects as <child> ?
    I think something like this is better:
    Code:
    <packmanobjects>
        <packmanobject name="obj1">
        <packmanobject name="obj2">
        <packmanobject name="obj3" parent="obj1">
    </packmanobjects>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •