Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 10th, 2007, 11:43 AM
Authorized User
 
Join Date: Apr 2006
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default processing instruction vs. element

I am confused between supporting page numbers in our application. The choices I have are as an element or as a processing instruction. Which is better, and why? I see the advantage of being able to link to a page number if implemented as an element, since you can't do that in a processing instruction.
what I would like to know is what can I do with a processing instruction that I can't do in an element, and visa versa.

Thanks,
Bill

 
Old April 10th, 2007, 12:01 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The only two differences that seem important are:

1. Elements can have attributes and children, processing instructions can't.

2. The existence and content of an element can be constrained by a DTD or schema. Processing instructions are not subject to such constraints. They can appear anywhere and they can contain arbitrary text.

and perhaps 3: Everyone uses elements and understands them. Hardly anyone uses processing instructions.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 10th, 2007, 12:09 PM
Authorized User
 
Join Date: Apr 2006
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Mike. This helps a lot.

2. The existence and content of an element can be constrained by a DTD or schema. Processing instructions are not subject to such constraints. They can appear anywhere and they can contain arbitrary text.
This is interesting. That means we can have some weird results if the XML file is not checked carefully. But can you please give me an example of arbitary text?

The only advantage I see for using processing instruction is there is no need to send out a new version of your software! do you agree?

Bill

 
Old April 10th, 2007, 12:21 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>But can you please give me an example of arbitary text?

E'WIORVB

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 10th, 2007, 12:24 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>The only advantage I see for using processing instruction is there is no need to send out a new version of your software! do you agree?

I've been known to use them to trigger processing by an XSLT stylesheet. For example

<?current-date?>

causes the stylesheet to insert the current date. The advantage of using a PI rather than an element <current-date/> is, I suppose, that you don't have to change the DTD/Schema (or negotiate with the owner of the DTD/Schema). The disadvantage is that what you've done isn't documented in the DTD/Schema, which is where people will tend to look when they want to know what game you're playing at.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 10th, 2007, 12:25 PM
Authorized User
 
Join Date: Apr 2006
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You mean if I have a page number as a processing instruction, this will be valid and display without a problem!
<?page E'WIORVB?>

 
Old April 10th, 2007, 03:46 PM
Authorized User
 
Join Date: Apr 2006
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Mike for making all this more clear to me.

Bill






Similar Threads
Thread Thread Starter Forum Replies Last Post
repetitive instruction, more efficient solution? stolte XSLT 4 November 27th, 2007 02:41 PM
xsl:result-document instruction bonekrusher XSLT 3 April 12th, 2007 06:01 PM
Help in instruction string-replace hugoscp XML 9 October 20th, 2006 12:07 PM
Create processing instruction in XSL hbcontract XML 6 May 7th, 2004 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.