• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get rid of this exception?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to parse the following xml
<?xml version="1.0" encoding="UTF-8" ?>
<Root>
< Global >
< Token >R< /Token>
< Force>0</Force>
</ Global>
< ServiceSettings>
< Service>
< ServiceName>A<ServiceName>
<TokenType>S</TokenType>
< Login>0</Login>
< Transaction>1</Transaction>
</ Service>
< Service>
< ServiceName>B<ServiceName>
<TokenType>RSA</TokenType>
< Login></Login>
< Transaction>0</Transaction>
</ Service>
</ ServiceSettings>
</Root>


Iam using following piece of java code to parse the above xml which I am getting from server in the form of MutableString(strConfigXML).

private Document m_document;
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
String strSrc = strConfigXML.toString();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(strSrc));
m_document = builder.parse(is);


Its giving the exception as
org.xml.sax.SAXParseException: The content beginning "< " is not legal markup. Perhaps the " " () character should be a letter.


Can anyone please guide me as I am new to Java and Xml as well?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Obviously, the input text is not what the parser expects at some point. This is a pretty common problem - something as simple as a leading space in front of the <?xml or a control code that is not legal UNICODE.

You can catch the SAXParseException and extract the line and column where the error occurred.

Bill
 
reply
    Bookmark Topic Watch Topic
  • New Topic