msphelix Posted September 25, 2012 Share Posted September 25, 2012 Hi,The XML DOM Tutorial sample file, books.xml, has a book node with 5 author nodes = multiple elements of the same type: <book category="web"> <title lang="en">XQuery Kick Start</title> <author>James McGovern</author> <author>Per Bothner</author> <author>Kurt Cagle</author> <author>James Linn</author> <author>Vaidyanathan Nagarajan</author> <year>2003</year> <price>49.99</price> </book> I understand doing it this way but I would tend to group the 5 authors as 5 sub-elements of one author element: <book category="web"> <title lang="en">XQuery Kick Start</title> <author> <data>James McGovern</data> <data>Per Bothner</data> <data>Kurt Cagle</data> <data>James Linn</data> <data>Vaidyanathan Nagarajan</data> </author> <year>2003</year> <price>49.99</price> </book> The pros of doing it the Tutorial's way are a smaller file and slightly easier access to the actual author names.The con is that, to me at least, it makes it harder to see all of the authors - I actually said "a book node with 2 author nodes" before I looked more closely.The pro of doing it my way is that all of the actual author data is in one element separate from the other elements and, for me at least, easier to see.The con is a bigger file and slightly more difficult access to the actual author names.My questions are:is there an XML standard that says the Tutorial's way is THE way it should be done?would someone looking at my XML think it was not up to standard?if there is no standard, which method do you prefer and why?Thanks Link to comment Share on other sites More sharing options...
Ingolme Posted September 25, 2012 Share Posted September 25, 2012 There are no rules to XML, besides making sure that the syntax is OK. If instead of calling your nodes <data> you call them <author> and put them in an <authors> element it's just as easy to acess the <author> nodes in both examples. bookElement.getElementsByTagName("author") Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now