Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
| 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 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
  #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.

  #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 &

  #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?

  #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 !

  #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.

  #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...

  #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

  #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 !!!

  #9 (permalink)  
Old July 26th, 2008, 03:40 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
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
  #10 (permalink)  
Old July 26th, 2008, 03:43 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
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




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





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