#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    48
    Rep Power
    12

    ERROR while XML is accessed using JAXP API and DOM parser


    Hi,

    when i tried to parse the xml document using DOM parser from JAXP API,
    I got an error...

    org.xml.sax.SAXParseException: XML declaration may only begin entities.
    at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3182)
    at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3170)
    at org.apache.crimson.parser.Parser2.maybePI(Parser2.java:966)
    at org.apache.crimson.parser.Parser2.maybeMisc(Parser2.java:1092)
    at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:487)
    at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
    at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)

    at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl
    .java:185)
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:151)
    at XMLBean.getCustInfo(XMLBean.java:34)
    at XMLBean.main(XMLBean.java:122)


    When I printed the line number out, it showed the line where my processing instruction of XML is coded(i.e.,<?xml version="1.0" ?>).
    here it goes....

    custinfo.xml
    ------------
    <!-- Name: Srivalli Chavali
    DateSubmited: 4/15/03
    Purpose: XML file to store Customer information of VegDeliPlus-->

    <!--sdfdf-->
    <?xml version="1.0" ?>

    <!-- DTD to define the language for VegDeliPlus customers -->
    <!DOCTYPE custlist [
    <!ELEMENT custlist (cust+)>
    <!ELEMENT cust (name, amtowed, addr, numpeople)>
    <!ELEMENT name (#PCDATA)>
    <!ELEMENT amtowed (#PCDATA)>
    <!ELEMENT addr (#PCDATA)>
    <!ELEMENT numpeople (#PCDATA)>
    <!ATTLIST cust credrating (1|2|3) #REQUIRED>
    <!ATTLIST numpeople good (Yes|No) "No">
    ]>

    <!-- VegDeliPlus Database as an XML file -->
    <custlist>
    <cust credrating="1">
    <name>James Gosling</name>
    <amtowed>$0.00</amtowed>
    <addr>12 Java Lane</addr>
    <numpeople>6</numpeople>
    </cust>
    <cust credrating="3">
    <name>Ronda Smith</name>
    <amtowed>$85.50</amtowed>
    <addr>345 Rocky Rd.</addr>
    <numpeople good="Yes">25</numpeople>
    </cust>
    <cust credrating="2">
    <name>Larry Lake</name>
    <amtowed>$255.85</amtowed>
    <addr>249 Lakeview Blvd.</addr>
    <numpeople good="Yes">112</numpeople>
    </cust>
    <cust credrating="1">
    <name>Sally Snow</name>
    <amtowed>$1,000.00</amtowed>
    <addr>11 Snowbird Blvd.</addr>
    <numpeople>19</numpeople>
    </cust>
    <cust credrating="2">
    <name>Ron Padova</name>
    <amtowed>$1,000.00</amtowed>
    <addr>282 East 12th St.</addr>
    <numpeople good="Yes">20</numpeople>
    </cust>
    <cust credrating="3">
    <name>Sue Jones</name>
    <amtowed></amtowed>
    <addr>45 Ruler Rd.</addr>
    <numpeople>4</numpeople>
    </cust>
    <cust credrating="1">
    <name>Robert Trent</name>
    <amtowed>$240.00</amtowed>
    <addr>23 Golfway Ave.</addr>
    <numpeople good="Yes">24</numpeople>
    </cust>
    <cust credrating="2">
    <name>LiChing Wu</name>
    <amtowed>$45.55</amtowed>
    <addr>873 Richmond Rd.</addr>
    <numpeople>13</numpeople>
    </cust>
    <cust credrating="2">
    <name>Narasimhiah Patel</name>
    <amtowed>$45.55</amtowed>
    <addr>26 Oakview Rd.</addr>
    <numpeople good="Yes">28</numpeople>
    </cust>
    <cust credrating="1">
    <name>Rachel Carter</name>
    <amtowed>$25.00</amtowed>
    <addr>1122 Erieview Ave.</addr>
    <numpeople>18</numpeople>
    </cust>
    <cust credrating="3">
    <name>Tom Tally</name>
    <amtowed>$0.00</amtowed>
    <addr>25 TallyHo Rd.</addr>
    <numpeople good="Yes">77</numpeople>
    </cust>
    </custlist>
    ----------------------------------------------------------------
    I cannot understand whats wrong in it.
    If I run my program removing the statement <?xml version="1.0" ?> from this custinfo.xml file, it WORKS FINE.
    Can anyone please tell me what the problem in that statement is?
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    I think the line
    Code:
    <?xml version="1.0" ?>
    HAS to be the first line. You have comments before it.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    48
    Rep Power
    12
    Oh! Great!
    Thanks a lot, Nemi...its working!!!

IMN logo majestic logo threadwatch logo seochat tools logo