|
ISBN is a property of the book, and there is a single instance, so it can be an attribute, or an element.
For properties or children that have more than one occurence, relying on elements is necessary. (To be honest, not really too, one could concatenate all element content within a single line, adding a separator in much the same way than CSV files).
All in all, you can think of attributes as a facultative tool to preserve size.
The use of Xml elements increase the overall size of Xml streams, even when they have no children, and that's because of the markers : <, >, /.
After all, everything in Xml could be made available as elements, and only elements.
The trouble is those people from the W3C have messed the thing up about Xml by introducing attributes, headers like ?xml, doctype, ... which are not written using the Xml syntax, and of course that stinking DTD format, which is not expressed in Xml either.
|
|
|
|
|
.S.Rod. wrote:
and of course that stinking DTD format
Long live XSD
"I will find a new sig someday."
|
|
|
|
|
The way I do it is, if something is a container, then it has subnodes. For example, if you're describing a menu in XML:
<menu>
<menuitem type='command' text="Run MS Word' program='winword.exe' />
<menuitem type='separator' />
<menuitem type='command' text="Run MS Excel' program='excel.exe' />
</menu>
A <menu> is a container for other things (items). A <menuitem> itself is just a thing, but it has various properties (type, text for the menu, and what app to run). Since those properties are simple values, they go as attributes.
In your sample, there is no reason to have title and price as nodes IMHO.
|
|
|
|
|
Michael,
In your example what happens when I have multiple languages. IMO "Title" should should be an element. You do not know how weird it feels suggesting this. Generally I am surrounded by those taught never to use attributes for anything, so I fight for them as proper usage.
"I will find a new sig someday."
|
|
|
|
|
Michael A. Barnhart wrote:
what happens when I have multiple languages
Then suddenly you have a container of titles.
<titles>
<title language='US English'>The Color of Money</title>
<title language='UK English'>The Colour of Money</title>
</titles>
Michael A. Barnhart wrote:
I am surrounded by those taught never to use attributes for anything
That's rather silly (just like most "NEVER DO xyz!" rules in programming) but whatever floats their boat, I guess.
--Mike--
I'm bored... Episode I bored.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
I think it really is a judgement call most of the time. My call is that core information which is always there and unique to that node should be an attribute. So ISBN is in, author and title are out.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Christian Graus wrote:
core information which is always there and unique to that node should be an attribute. So ISBN is in, author and title are out.
<joke>you can't have written a book. If you had, you would take a lot more serious the association of a book and the author.</joke>
|
|
|
|
|
*grin* How apt - tags in a post on the XML board.
I realise you were kidding, but just in case the joke was borne out of my lack of clarity, my point is that more than one book can have the same author, therefore it's not unique and so not an attribute.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
OK, I know what XML is (I think) but I still don't "get it". So here are a couple questions for discussion:
What are the pros and cons of XML?
What problems does XML solve?
When is XML a good solution for a problem, and when isn't it?
Self-defining data structure. So what? What's a real-world example where this is actually used? It seems like a great idea, but implementation is non-trivial.
I have had several people comment to me that I should use XML instead of a flat file. Why? Just because its structured? So what? A spreadsheet is structured, that doesn't mean it should be formatted in XML, does it? It seems that XML is inefficient space wise, parsing is slow, and human readability is poor. If data is supposed to be human readable, then make it human readable, and if its supposed to be machine readable, then make it machine readable. XML seems to be a hybrid that doesn't do either very well.
Marc The XML Skeptic
Help! I'm an AI running around in someone's f*cked up universe simulator. Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus Every line of code is a liability - Taka Muraoka
|
|
|
|
|
Marc Clifton wrote:
What problems does XML solve?
For starters, unlike a relational table, an XML file has no limits. You can create a subnode and put as many of them in as you like. XML also puts your data into a format where it can be shaped with XSL, formatted with XSLFO, verifed with XSD and rendered with SVG.
Marc Clifton wrote:
When is XML a good solution for a problem, and when isn't it?
Like any 'magic bullet', XML can be overused. But I'm not sure it ever does any harm. It's a good solution if you ever want any of the things I mentioned, and when you want to share your data.
Marc Clifton wrote:
Self-defining data structure. So what? What's a real-world example where this is actually used? It seems like a great idea, but implementation is non-trivial.
The greatest strength of XML is not when it's a free form thing that defines itself, but when you've defined a structure you want to use ( like a db schema ) and when you use the namespaces already defined, such as XSL.
XML gives you a format which makes your data easy to work with in a variety of ways, and an API for parsing/searching it that works very well when you add XPath to the equation.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Thanks Christian, that was very helpful, especially how you outlined the use of XML, XSL, XSLFO and XSD. Now I've got another thing to look up "XSLFO".
and when you use the namespaces already defined, such as XSL.
Ah, that sort of clarifies a big confusion that I have, which has to do with who defines the definition?
...XPath to the equation.
What are your thoughts regarding the difference between XPath and XQuery?
Marc
Help! I'm an AI running around in someone's f*cked up universe simulator. Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus Every line of code is a liability - Taka Muraoka
|
|
|
|
|
Marc Clifton wrote:
What are your thoughts regarding the difference between XPath and XQuery?
Well XPath is used to define where to get the data you want to process and XQuery is used to find data that fits some bounds. Not the same task, or am I missing your question?
"I will find a new sig someday."
|
|
|
|
|
Christian Graus wrote:
For starters, unlike a relational table, an XML file has no limits. You can create a subnode and put as many of them in as you like. XML also puts your data into a format where it can be shaped with XSL, formatted with XSLFO, verifed with XSD and rendered with SVG.
Is it me or ? I don't see the Asteroids link.
Christian Graus wrote:
it can be formatted with XSLFO
Let's be realistic :
<theory>it can be formatted with XSLFO</theory><practice></practice>
|
|
|
|
|
Marc Clifton wrote:
Just because its structured?
No so much that as it has a basic structure that allows anyone to do basic manipulation of the data, even without having a clue as to where the data came from. You could invent your own flat, text-based storage protocol but only your app would ever understand it. It might be human-readable (a big plus) but another app would be stumped.
It's also extensible in the sense that if you see something you don't recognize, you can just ignore it. I want to do something like this for my RSS reader: allow publishers to pump out standard RSS plus whatever extra stuff they want to embed (using namespaces). Then, as long as it's syntactically correct, I just pass it on verbatim to a plugin who can do whatever they want with it. Try doing that with a home-grown format.
And everyone uses it. Not a very good argument but you use Windows, right...?
Taka The Former XML Skeptic
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed)
Awasu v0.4a[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
Thanks Taka, that helped clarify a few things, especially the part about ignoring data you don't understand and passing it along to something else. This sort of reminds me of a TCP/IP protocol stack.
For some reason I'm having a really hard time getting my arms around this.
And everyone uses it.
grrrr.
Marc
Help! I'm an AI running around in someone's f*cked up universe simulator. Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus Every line of code is a liability - Taka Muraoka
|
|
|
|
|
The application that I'm currently looking at XML for is to make my data human readable (power user, not normal user!!) and enable them to customise reporting, formatting and querying of the data. I see access to XSLT functionality as being the main reason to use XML.....
|
|
|
|
|
The application that I'm currently looking at XML for is to make my data human readable (power user, not normal user!!) and enable them to customise reporting, formatting and querying of the data. I see access to XSLT functionality as being the main reason to use XML.....
Out of curiosity, why is XML a better solution for you than a database using SQL to query and format simple things and using existing reporting tools for more complicated reporting?
Marc
Help! I'm an AI running around in someone's f*cked up universe simulator. Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus Every line of code is a liability - Taka Muraoka
|
|
|
|
|
We are looking at low (computer) skill, price sensitive users.
XSLT was considered easier for our userbase to understand - or at least not mess up too badly, then SQL.
ASCII files that could easily be edited was also considered an advantage.
The inclusion of XML on (most) windows systems (our only target platform) without royaltys etc.
We need/would like to support the input/output of a number of already existing XML schema. (Is this "because everyone else is doing it"?) These Schema map poorly to our system, and we have a history of "lookup" and "mapping" files. XSLT will hopefully remove a lot of that from our coding.
We have not yet released anything XML, so what the actual reality is remains to be seen!!!!
|
|
|
|
|
I generally agree with Christians response but here are my 2 cents.
Marc Clifton wrote:
What are the pros and cons of XML?
Pros. You can create and transmit your data in an XML format with your tool set and I can read it with my tool set. Language and platform independant. No need to write a custom routine for each set of data (other than using the parsing tools in my app. If you have documented your information with a schema I can test your file and see if it conforms. You can also test my data when I return info to you. I can extend your data with additional info and extend your schema if needed. Your data is still consistent and usable with my additions doing nothing to the processing sequence of yoru data. Where do I stop?
Cons. TO many people believe in magic. Since XML is the in buzz word it will be missued and then discarded as not being a good solution when it may be.
Marc Clifton wrote:
What problems does XML solve?
For me it is mostly data transmission and reformating. I have a lot of data that must be displayed for review and then used in applications. I can XMLize the data stream from the data source and then apply the appropriate transformation for the usage at hand. This now gives me one authoritive data source for all usage. I can not tell you how many millions of dollars I know have been lost due to not having one authoritive set of data, but multiple that were not really handled correctly.
Marc Clifton wrote:
When is XML a good solution for a problem, and when isn't it?
Rather open question. It is a good solution to the above items that I mention plus more. It is not a good solution to use for massive data migration tasks. For example I have done a lot of finite element work. Now a typical run may produce a binary data set that is say 20 gig in size. It would be rediculus to handle this entire set of data as an XML file. If you just need to send a small set of data from a query then query the data and XMLize the results to send.
Marc Clifton wrote:
Self-defining data structure. So what?
Not just self defining structure but in the way it is structured. The ability to now use XPath and XSLT to find and process what I need as well as a standard method to describe the data schema is very powerfull. How do I process your flat file with my tool set?
Marc Clifton wrote:
It seems that XML is inefficient space wise, parsing is slow, and human readability is poor.
OK compared to what. ASCII is inefficient so lets ban that. The question is what do we gain. Now as stated earlier you can missuse it.
Parsing is slow, again compared to what? Parsing is much faster than me having to open your file and copy and paste the data I need.
Readability: have you ever had to go sort out a flat file that did not have the proper documentation or worse a binary. I have had to do both.
Now if none of the above impacts you XML may very well not apply to your task. It is not a magic solution that solves all of the worlds problems.
You mentioned your flat file. You may ask yourself how it is being used. Only for your app which never needs to be transfered or migrated? Then leave it be. It may be best to add export import to your solution than to use XML as the native format. THen if you do need these options you have it built in.
"I will find a new sig someday."
|
|
|
|
|
Thanks Michael, that put some things into perspective. Particularly your last comment--Only for your app which never needs to be transfered or migrated? This was something that was bothering me--people were recommending I use XML when the flat file is really application specific--none of the data needs to be transmitted to another app.
It seems that XML is a good tool to use when transferring data between applications is an issue.
But from what you and others have said, it also seems that it is a good tool for parsing and validation, regardless of inter-application issues.
The thing that bothers me is that I can, for example, edit a flat file that describes a menu structure much more easily that I can edit a similar XML file. It seems that even simple data structures need some sort of an editor to make the data more user friendly. Thoughts?
Marc
Help! I'm an AI running around in someone's f*cked up universe simulator. Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus Every line of code is a liability - Taka Muraoka
|
|
|
|
|
Marc Clifton wrote:
The thing that bothers me is that I can, for example, edit a flat file that describes a menu structure much more easily that I can edit a similar XML file.
For something like an outline of a book. I absolutly agree.
Marc Clifton wrote:
But from what you and others have said, it also seems that it is a good tool for parsing and validation, regardless of inter-application issues.
Yes but for interapp usage I would think once the tools have been tested this in not the issue that it is for data between apps and companies.
Marc Clifton wrote:
It seems that even simple data structures need some sort of an editor to make the data more user friendly. Thoughts?
I would not plan for the raw XML file to be edited and manipulated by end users if this is a common task to be done. Yes go create an editor if the data is XML or not.
Now if the data is available in XML (native or export/import) then if a power user does need to do something the likely hood that they can figure it out is much greater. They can then create the editor they need for their task with your format. I would also expect to have a schema available. My band wagon here. Please use XSD and not DTD's, why use non-XML to describe XML.
"I will find a new sig someday."
|
|
|
|
|
XML is a readable compound document file format (IStorage/IStream folders/files metaphore). At each level you may have an arbitrarily deep set of children, and so on. That's why it simplifies versioning a lot over time : no need to break a file format, just add new storages.
|
|
|
|
|
I have this code snipet in my c# classs that generates a string containg xml data.
//build xml data
StringWriter xmlStringWriter = null;
XmlTextWriter xmlWriter = null;
string xmlString = "";
StringBuilder xmlStringBuilder = new StringBuilder();
try
{
xmlStringWriter = new StringWriter(xmlStringBuilder);
xmlWriter = new XmlTextWriter((xmlStringWriter);
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.WriteStartDocument(); //start document
//populate xml
However, the generated xml string contains the header as:
Does anybody know of a way to use enconding "utf-8" when building an xmldoc inside a string?
|
|
|
|
|
It appears that you did not check the display message as-is (no HTML).
Are you trying to save an XML document inside a single string to then include in a second instance of something else (be it a XML doc or what ever?)
"I will find a new sig someday."
|
|
|
|
|
I have a problem with converting all serialized data of MFC Object such as COleClientItem, CDocItem and CObject to XML. I would appreciate it if someone could suggest me how to solve this problem.
Thank very much for your help.
|
|
|
|
|