Entity References?

Posted on 2003-02-28
Medium Priority
Last Modified: 2013-11-19
Please tell me under what circumstance I will need to use the < and > entity references. I read somewhere that they might come in handy when representing a path to a directory in my xml code eg

<location> Locate the web.xml file in the &lt;path&gt;/bin directory </location>

I know that this tranlates to

<location> Locate the web.xml file in the <path>/bin directory </location>

But I dont understand why you will need "non-xml" < and > tags in your xml code. Thanks.
Question by:ogeikem
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 8046340
if you used "<path>", the XML parser will think ( rightly so ) that 'path' is a tag. Since you dont have a "</path>" closing tag, this will cause an exception in the xml parser. For this reason, '<' and '>' are not allowed as data in XML.
Using & lt;  or & gt;  kinda sucks, because this is HTML. You might as well use ANY character or character sequence to represent your '<' and '>' as long as you know what you are looking for.  Alot of times, people will use the lt and gt because they figure, "what the hey, its all html in the end." and kill two birds with one stone, so to speak.  Personally, I see ourselves explaining this one to our kids one day. "Daddy, why do we have to use this &lt and &gt in our XML?". "Well, son. You see there was once this thing called HTML..."
Anyway, your parser will hate you for putting '<' and '>' in your data.  Unless you want to skip validation and write your own SAX handler to handle '>' and '<'. ;-)

Author Comment

ID: 8046491
Thanks for the comment. I understand how entity references were used to represent '<' and '>' in this xml code. What I dont understand is why anyone would need non-xml '<' and '>' tags in their xml code. I thought xml was used to deliver pure text and not tags.

Accepted Solution

functionpointer earned 80 total points
ID: 8046504
I work for a company that writes applications for financial institutions. You would not believe how many times "less than" and "greater than" get passed around. Whether we like it or not, less intelligent people enter this info into other apps, it gets put in databases, and gets pulled out and put in XML documents/messages to be sent elsewhere. '>' and '<' are just ascii characters, and as long as they keep putting them on the keyboard, like sharp objects, stupid people will continue to hurt themselves.

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question