One , What happened to the problem :

j be based on java Language webservic The server receives the client From the xml String use Analysis time report :org.dom4j.DocumentException: Error on line 1 of document  :  No content is allowed in the foreword . Nested exception:  No content is allowed in the foreword .

xml The string format is :

Two , Question why :

From the pictures we can see that ,XML File format 、 There are no mistakes in the content , Baidu problems are all caused by coding problems ,

After investigation, we found that xml The encoding format specified in is utf-8, The data format sent by the client is gbk Format

3、 ... and , Solution :

Will be xml character string Recode ,new String(text.getBytes("gbk"),"utf-8"); Further analysis will solve the problem

Four , reflection :

Here is the analysis xml character string , analysis xml Document homology , If the file format is inconsistent with the specified code in the file, this type of error will also be reported , At this point, you just need to use something like notepad++ The tool unifies the file types   One can .

Another implementation ant When compiling a program , For example, modify the configuration directly in the compiled program xml File time, execute time , I've seen this kind of mistake , Just recompile and change the configuration xml The file error disappears , This is not very common , Record it here .

analysis xml String times “ No content is allowed in the foreword ” error . More articles about

  1. Use Rome Read RSS Report errors ,org.xml.sax.SAXParseException: No content is allowed in the foreword .

    This is the most wonderful mistake I've ever made new URL When , Using static variables will report an error org.xml.sax.SAXParseException: No content is allowed in the foreword . URL url = new URL(Strin ...

  2. “Nested exception: No content is allowed in the foreword " Error handling

    I'm working on a small project recently , Use org.dom4j.DocumentHelper.parseText Method has been reported error ”Nested exception: No content is allowed in the foreword ", This parseText Explain ...

  3. Use spring rest Something happened while inserting the database No content is allowed in the foreword error

    This error is usually caused by coding , Like asking for post When , Used application/x-www-form-urlencoded Of content type So the request came string You need to use urlDe ...

  4. About SAXParseException Content is not allowed in Prolog ( No content is allowed in the foreword )

    analysis XML When you file , Such as Mybatis Of Mapper file , Sometimes there will be  org.xml.sax.SAXParseException No content is allowed in the foreword   It's abnormal , English is  Content is ...

  5. SAXParseException Content is not allowed in Prolog ( No content is allowed in the foreword )

    analysis XML When you file , Such as Mybatis Of Mapper file , Sometimes there will be org.xml.sax.SAXParseException No content is allowed in the foreword It's abnormal , English is Content is ...

  6. dom4j analysis xml String instances

    DOM4J And use DOM.SAX.JAXP Mechanism to analyze xml comparison ,DOM4J Better performance , Excellent performance . Powerful and extremely easy to use features , As long as you know DOM Basic concepts , You can go through dom4j Of api Document to parse xml ...

  7. org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException No content is allowed in the foreword From classpath resources XML Number... In the document 1 Line is invalid

    Review today Spring and Hibernate Integration of , There's a problem , The error information is as follows : org.springframework.beans.factory.xml.XmlBeanDefinitionSto ...

  8. C++ analysis XML character string

    There is a need for project interaction VC++ Chinese analysis XML character string , So it took a little time to get to know VC++ Chinese analysis XML There are three main ways to do it :msxml( Microsoft provides ).markup.TinyXml. It took a little time to use msxml3, though ...

  9. About xml Loading tips : Error on line 1 of document : No content is allowed in the foreword

    I was in java Related tests done in , First, paste the error report : Read xml The configuration file :xmls\property.xml org.dom4j.DocumentException: Error on line 1 of ...

Random recommendation

  1. xml Basic summary

    Extensible markup language (eXtensible Markup Language) advantage : Easy to read : Format standards are built into any language XML Analysis engine , There is no need to write the file analysis engine separately . The disadvantage of using ordinary binary to transmit data , Analytical way ...

  2. RocketMQ Learning record

    RocketMQ It's a distributed . Message middleware of queue model , It has the following characteristics : 1. Can guarantee strict message order  2. Provides rich message pull patterns  3. Efficient subscriber level scalability  4. Real time message subscription mechanism  5. 100 million message stacking capacity ...

  3. logback.xml_appender To configure

    logback<appender> <appender>: <appender> yes <configuration> Child nodes of , It's the component responsible for writing logs . < ...

  4. CorePlot Learning zero --- install

    Just beginning to touch CorePlot when , I found many related articles on the Internet , Explain how to install the third party library , At this stage, the version number of the library has arrived 1.5 了 , But in the github You can see his installation method on the Internet , It's just why there's no codpod To install ? ...

  5. HDU2579

    Dating with girls(2) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  6. android Delay the

      Deferred execution can be achieved by , List them in the recommended order 1. new Handler().postDelayed(new Runnable(){ public void run() { //execut ...

  7. Python3.5 Learning notes - File operations

    stay Python in , Manipulate file objects using open Function to create , The following table lists the common operations file Function of : Serial number   Method and description 1.file.close() Close file . After closing, the file can no longer be read or written . 2.file.fl ...

  8. XP Next Unable to locate program entry point WSAPoll In dynamic link library ws2_32.dll Solutions for

    Recently, when enabling the black threshold service for mobile phones, it is impossible to locate the program input point WSAPoll In dynamic link library ws2_32.dll This mistake , I checked online because SDK Platform Tools The version is too high to be compatible windows xp ...

  9. Raspberry pie nfs server install

    Installation services sudo  apt-get install  portmap sudo  apt-get install  nfs-kernel-server To configure : sudo nano /etc/expo ...

  10. answer VS2013 What's the reason for inaccurate compilation error

    1. When the program is in error ,VS2013 Sometimes, all the errors reported by compilation will not be reported together , It's called out one by one according to the wrong initials 2. If you double-click the error information and find that there is no obvious error problem when you check it , This time can be VS Compilation cache problem , this ...