What is wrong? The minidom or the XML file?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anthony Liu

    What is wrong? The minidom or the XML file?

    I copy-pasted the following sample xml document from
    http://slis-two.lis.fsu.edu/~xml/sample.html and saved
    it as samplexml.xml. Please note that I removed the
    following line

    <!DOCTYPE DOCUMENT SYSTEM "simple.dtd ">

    from the original xml sample.

    <?XML version="1.0" encoding="UTF-8"?>
    <DOCUMENT trackNum="1234" >
    <TITLE> Sample Document </TITLE>
    <AUTHOR> <FIRSTNAME> Brandon </FIRSTNAME>
    <LASTNAME> Voss </LASTNAME>
    <COMPANY> The XML Pages </COMPANY> </AUTHOR>
    <SUMMARY> This is element text and an entity
    follows:&Descri ption;
    </SUMMARY>
    </DOCUMENT>

    Then, I attempted to parse this xml document with the
    following python code, which is saved as xmltest.py.

    from xml.dom import minidom
    xmldoc = minidom.parse(' sample.xml')
    print xmldoc.toxml()

    I got the following error message:
    [color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]

    Traceback (most recent call last):
    File "C:\Python23\co des\xmltest.py" , line 4, in
    -toplevel-
    xmldoc = minidom.parse(' samplexml.xml')
    File "C:\Python23\li b\xml\dom\minid om.py", line
    1919, in parse
    return expatbuilder.pa rse(file)
    File "C:\Python23\li b\xml\dom\expat builder.py", line
    924, in parse
    result = builder.parseFi le(fp)
    File "C:\Python23\li b\xml\dom\expat builder.py", line
    207, in parseFile
    parser.Parse(bu ffer, 0)
    ExpatError: not well-formed (invalid token): line 1,
    column 5[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]

    I have no clue why that xml document is not
    well-formed.

    Any hint please?


    _______________ _______________ ____
    Do you Yahoo!?
    Yahoo! Search - Find what you’re looking for faster
    The search engine that helps you find exactly what you're looking for. Find the most relevant information, video, images, and answers from all across the Web.


  • Erik Max Francis

    #2
    Re: What is wrong? The minidom or the XML file?

    Anthony Liu wrote:
    [color=blue]
    > <?XML version="1.0" encoding="UTF-8"?>[/color]
    ^
    ...[color=blue]
    > ExpatError: not well-formed (invalid token): line 1,
    > column 5[/color]

    Line 1 column 5 is the L in <?XML. That XML document type declaration
    is invalid; the "XML" needs to be in lowercase.

    --
    __ Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
    / \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
    \__/ It's like being on a diving board that you know is too high.
    -- Sade Adu

    Comment

    • Peter Abel

      #3
      Re: What is wrong? The minidom or the XML file?

      Anthony Liu <antonyliu2002@ yahoo.com> wrote in message news:<mailman.2 13.1078910068.1 9534.python-list@python.org >...[color=blue]
      > I copy-pasted the following sample xml document from
      > http://slis-two.lis.fsu.edu/~xml/sample.html and saved
      > it as samplexml.xml. Please note that I removed the
      > following line
      >
      > <!DOCTYPE DOCUMENT SYSTEM "simple.dtd ">
      >
      > from the original xml sample.
      >
      > <?XML version="1.0" encoding="UTF-8"?>
      > <DOCUMENT trackNum="1234" >
      > <TITLE> Sample Document </TITLE>
      > <AUTHOR> <FIRSTNAME> Brandon </FIRSTNAME>
      > <LASTNAME> Voss </LASTNAME>
      > <COMPANY> The XML Pages </COMPANY> </AUTHOR>
      > <SUMMARY> This is element text and an entity
      > follows:&Descri ption;
      > </SUMMARY>
      > </DOCUMENT>
      >
      > Then, I attempted to parse this xml document with the
      > following python code, which is saved as xmltest.py.
      >
      > from xml.dom import minidom
      > xmldoc = minidom.parse(' sample.xml')
      > print xmldoc.toxml()
      >
      > I got the following error message:
      >[color=green][color=darkred]
      > >>>[/color][/color]
      >
      > Traceback (most recent call last):
      > File "C:\Python23\co des\xmltest.py" , line 4, in
      > -toplevel-
      > xmldoc = minidom.parse(' samplexml.xml')
      > File "C:\Python23\li b\xml\dom\minid om.py", line
      > 1919, in parse
      > return expatbuilder.pa rse(file)
      > File "C:\Python23\li b\xml\dom\expat builder.py", line
      > 924, in parse
      > result = builder.parseFi le(fp)
      > File "C:\Python23\li b\xml\dom\expat builder.py", line
      > 207, in parseFile
      > parser.Parse(bu ffer, 0)
      > ExpatError: not well-formed (invalid token): line 1,
      > column 5[color=green][color=darkred]
      > >>>[/color][/color]
      >
      > I have no clue why that xml document is not
      > well-formed.
      >
      > Any hint please?
      >
      >
      > _______________ _______________ ____
      > Do you Yahoo!?
      > Yahoo! Search - Find what you?re looking for faster
      > http://search.yahoo.com[/color]

      One additional possibility to get another quick help about errors
      in the xml-document is - when working under MS-Windows - to open
      the document with the Internet Explorer up from version 5.xx
      or so.
      In your case it tells me exactly what Erik Max Francis told you.

      Regards
      Peter

      Comment

      Working...