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

July 26th, 2008, 12:00 AM
|
|
Authorized User
|
|
Join Date: Mar 2008
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

July 26th, 2008, 12:57 AM
|
|
Authorized User
|
|
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
& has to be written as an entity : & instead of &
|
|

July 26th, 2008, 01:01 AM
|
|
Authorized User
|
|
Join Date: Mar 2008
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by Alain COUTHURES
& has to be written as an entity : & 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?
|
|

July 26th, 2008, 01:03 AM
|
|
Authorized User
|
|
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
No way... This XML document is not valid !
|
|

July 26th, 2008, 01:08 AM
|
|
Authorized User
|
|
Join Date: Mar 2008
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

July 26th, 2008, 01:18 AM
|
|
Authorized User
|
|
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
XML is a notation with principles : & has to be written & 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...
|
|

July 26th, 2008, 01:25 AM
|
|
Authorized User
|
|
Join Date: Mar 2008
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

July 26th, 2008, 01:33 AM
|
|
Authorized User
|
|
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Since "Johnson & Johnson" is not written "Johnson & 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 !!!
|
|

July 26th, 2008, 03:40 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
& in XML must always be written &
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
|
|

July 26th, 2008, 03:43 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
>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 |
|
 |