Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 26th, 2008, 12:00 AM
Authorized User
 
Join Date: Mar 2008
Location: , , .
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default Parsing the xml which is having

Hi,

When i try to parse an xml file, its giving the following SAXParserException:

The entity name must immediately follow the '&' in the entity reference.

The xml is as below :

<Request>
 ...
 <OfficeName>Johnson & Johnson</OfficeName>
..
</Request>

This xml is generated from an external program. So while validating this xml, using my xsd i am getting the above mentioned exception.

The corresponding schema part is as below:

<xs:element name="OfficeName">
  <xs:simpleType>
    <xs:restriction base="xs:string">
            <xs:maxLength value="32"/>
    </xs:restriction>
   </xs:simpleType>
/xs:element>

Please help me to resolve this issue. Thanks in advance for your help.

Reply With Quote
  #2 (permalink)  
Old July 26th, 2008, 12:57 AM
Authorized User
 
Join Date: Apr 2008
Location: Bordeaux, , France.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

& has to be written as an entity : &amp; instead of &

Reply With Quote
  #3 (permalink)  
Old July 26th, 2008, 01:01 AM
Authorized User
 
Join Date: Mar 2008
Location: , , .
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Alain COUTHURES
 & has to be written as an entity : &amp; instead of &

Hi,

As this input xml is generated from external program, I just have to do validation and not any modification to the incoming xml. So here how to overcome this exception?

Reply With Quote
  #4 (permalink)  
Old July 26th, 2008, 01:03 AM
Authorized User
 
Join Date: Apr 2008
Location: Bordeaux, , France.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No way... This XML document is not valid !

Reply With Quote
  #5 (permalink)  
Old July 26th, 2008, 01:08 AM
Authorized User
 
Join Date: Mar 2008
Location: , , .
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Alain COUTHURES
 No way... This XML document is not valid !

How are you saying the xml doc. as invalid.In real time, it is possible to receive the '&' symbol in xml, as many oraganization's name having that. So in these kind of situation, there should be some way to handle this.

Reply With Quote
  #6 (permalink)  
Old July 26th, 2008, 01:18 AM
Authorized User
 
Join Date: Apr 2008
Location: Bordeaux, , France.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

XML is a notation with principles : & has to be written &amp; or has to be protected within a CDATA section. If so, & can be present in text data.

The external program you are talking of is not good for representing & the way it has to be...

Reply With Quote
  #7 (permalink)  
Old July 26th, 2008, 01:25 AM
Authorized User
 
Join Date: Mar 2008
Location: , , .
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok..Here, <OfficeName> node contains the value "Johnson & Johnson", which is a text value. So in order to accept '&' also in value of that node, how I have to write my schema

Reply With Quote
  #8 (permalink)  
Old July 26th, 2008, 01:33 AM
Authorized User
 
Join Date: Apr 2008
Location: Bordeaux, , France.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Since "Johnson & Johnson" is not written "Johnson &amp; Johnson" in the XML document, this document is not valid, it can't be parsed and, so, no schema can be checked.

The XML document has to be modified !!!

Reply With Quote
  #9 (permalink)  
Old July 26th, 2008, 03:40 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

& in XML must always be written &amp;

You need to fix the program that is generating this. It's a great idea for programs to generate output in XML, because so much software can accept XML. But if they generate stuff that isn't XML, it rather destroys the point.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
Reply With Quote
  #10 (permalink)  
Old July 26th, 2008, 03:43 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>As this input xml is generated

Please don't refer to it as XML. It isn't. You must either fix the program so it generates XML, or you must convert its non-XML output to XML. It would be much better to fix it, so you can share in the benefits that come from using XML for data interchange rather than using proprietary non-standard formats.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
parsing xml kri_hegde XML 5 July 24th, 2007 11:37 AM
XML parsing denzil_cactus Perl 0 June 11th, 2007 02:34 AM
XML Parsing SCADA_Monkey XML 2 March 11th, 2007 03:20 PM
XML Parsing tgopal Javascript 2 July 27th, 2004 08:54 AM
XML Parsing tgopal .NET Web Services 1 June 15th, 2004 03:25 AM



All times are GMT -4. The time now is 01:01 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.