|
Just my 2 cents here but why a old DTD format? For my area we only use XSD for new work.
Second what goal are you wanting? If it is to validate the file then use the existing tools. If it is to make a data entry form then I can see some use.
"I will find a new sig someday."
|
|
|
|
|
Thank you reply .
I want to write c program that parse dynamicly dtd file , get the element ,and take use of these element to parse xml file for getting the element't content
such as :
DTD file is GoodXml.dtd
-----------
<!ELEMENT bookshell (book*)>
<!ELEMENT book (author, title)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT title (#PCDATA)>
---------------------------------
XML file is GoodXml.xml
-----------------
<!DOCTYPE bookshell SYSTEM "GoodXml.dtd">
<bookshell>
<book>
<author>Du Peng Chao</author>
<title>Today Story</title>
</book>
</bookshell>
----------------------------------------------
firstly , the program parse GoodXml.dtd file ,get element "bookshell ,book,author,title ",
secondly, use the element to parse xml file ,
get the content "Du Peng Chao" and "Today Story"
of course ,I use libxml ,not write parser myself.
in a word ,parse dtd file dynamicly ,parse xml file dynamicly ,then get element content .
thank you in advance .
|
|
|
|
|
From what you describe I can just parse the XML file and get the tags and data from it. I do not get anything from reading the DTD.
"I will find a new sig someday."
|
|
|
|
|
Now I think I am wrong . because as you say , I can parse the xml file and get tags and data from it ,I need't parse dtd file , Yes ,it is a comprehension error .
OK ,thank you reply , I know how to do it
|
|
|
|
|
Hi, I try to use Jscript and XML together.
For example:
--------------------------------
<books>
...
<book title="Harry Poter">
<book title="Harry Poter">
...
----------------------------------
how can I read title attributes by using XMLDOM object.
And do you refer me any good tutorial about XMLDOM object use in jscript.
karanba
|
|
|
|
|
I like it.
Be sure to replace < with < in your post.
|
|
|
|
|
Here's a snipet from an MSDN example:
doc.LoadXml("<book ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" +
"<price>19.95</price>" +
"</book>");
Now, why is ISBN an attribute, not a node, vs. title and price? I've done a brief search to try and explain when something should be an attribute and when something should be a node, and I can't find a good explanation. It seems that price and title are attributes of a book too.
Comments?
PS - I'd like to thank all for answering my previous questions too! It is definitely helpful.
Marc
|
|
|
|
|
You get a lot of personal opinions here. Many say you should never use attributes. I do not agree with that but thought must be used in your placement. Our local guidance usually says for unique machine identifiable info we use attributibutes. For one even though you can have a schema that says you have only one child node of a given name this can be overridden. For an attribute you can only have one.
Now for your question: There is only one ISBN for a book (now I ask is that really true?) For the Title and Price you may want to have the title shown in many languages so you add all that you need and add a language attribute to the title block. Same for price, currencies, specials deal's etc. But they all point to the same book.
Now for the ISBN question. If a book is then printed in a new language does it get a new ISBN? I do not know but if so they may have restricted them selves by this format. However if you are tracking each book the above hold true and is probably their logic.
"I will find a new sig someday."
|
|
|
|
|
Michael A. Barnhart wrote:
machine identifiable
I should have stated info not shown to the standard user.
"I will find a new sig someday."
|
|
|
|
|
Ah. So the "typical" usage of an attribute is to qualify the node, for example, the language attribute qualifies the book title and the currency attribute qualifies the price.
That makes sense, but it seems that there are lots of exceptions, which I guess is why you get a lot of personal opinions.
Well, I like how you put it. It provides some good guidelines as to when to use an attribute or not.
It would seem then that David Stone's comment: You have elements(controls), attributes(properties), and it's all hierarchical(parent controls) would therefore be an inappropriate use of attributes. Properties of a control should be sub-nodes?
What about the concept that something could be an attribute if it is the lowest divisible piece of information? In David's example, something like width could then be an attribute (of course, what kind of width--pixels, dialog units, inches, etc)?
Oh boy.
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
|
|
|
|
|
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
|
|
|
|
|