Parsing error xml parsing error not well formed invalid token

I am working on an application, with following XML. but whenI try to clean/build my project the following error occurs: "error: Error parsing XML: not well-formed (invalid token)" <?xml versio...

I am working on an application, with following XML. but whenI try to clean/build my project the following error occurs:

«error: Error parsing XML: not well-formed (invalid token)»

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/hello";
/>
</LinearLayout>

What does it possibly mean?

Sree's user avatar

Sree

3,1162 gold badges31 silver badges39 bronze badges

asked Aug 17, 2011 at 8:19

Usama Sarwar's user avatar

Usama SarwarUsama Sarwar

8,8207 gold badges52 silver badges79 bronze badges

1

I had this problem, and when I had android:text="< Go back" it had the correct syntax highlighting, but then I realized it’s the < symbol that is messing everything up.

answered Jan 23, 2016 at 2:18

Rock Lee's user avatar

3

It means there is a compilation error in your XML file, something that shouldn’t be there: a spelling mistake/a spurious character/an incorrect namespace.

Your issue is you’ve got a semicolon that shouldn’t be there after this line:

  android:text="@string/hello";

answered Aug 17, 2011 at 8:21

Blundell's user avatar

BlundellBlundell

74.5k30 gold badges208 silver badges232 bronze badges

3

I had same problem. you can’t use left < arrow in text property like as android:text="< Go back" in your xml file. Remove any < arrow from you xml code.

Hope It will helps you.

answered Dec 29, 2016 at 6:17

Dalvinder Singh's user avatar

Dalvinder SinghDalvinder Singh

1,0831 gold badge12 silver badges19 bronze badges

1

Verify that you don’t have any spaces or tabs before

<?xml version="1.0" encoding="utf-8"?>

also refresh and clean your project in eclipse.

I get this error every now and then and the above suggestions fix the issue 99% of the time

answered Aug 17, 2011 at 8:23

Julian Suarez's user avatar

Julian SuarezJulian Suarez

4,4994 gold badges24 silver badges40 bronze badges

To solve this issue, I pasted my layout into https://www.xmlvalidation.com/, which told me exactly what the error was. As was the case with other answers, my XML had < in a string.

answered Apr 20, 2018 at 18:00

Alan Kinnaman's user avatar

Remove the semicolon after hello

answered Nov 30, 2013 at 9:12

Vincent Thacker's user avatar

I had the same problem. In my case, even though I have not understood why, the problem was due to & in one of the elements like the following where a and b are two tokens/words:

<s> . . . a & b . . . </s>

and to resolve the issue I turned my element’s text to the following:

<s> . . . a and b . . . </s>

I thought it might be the case for some of you. Generally, to make your life easier, just go and read the character at the index mentioned in the error message (line:..., col:...) and see what the character is.

answered Nov 18, 2019 at 0:10

Pedram's user avatar

PedramPedram

2,3462 gold badges29 silver badges45 bronze badges

In my case I forgot to end my ConstrainLayout

</android.support.constraint.ConstraintLayout>

After that, everything started working correctly.

answered Dec 6, 2018 at 10:18

Wiktor Kalinowski's user avatar

0

I tried everything on my end and ended up with the following.

I had the first line as:

<?xmlversion="1.0"encoding="utf-8"?>

And I was missing two spaces there, and it should be:

<?xml version="1.0" encoding="utf-8"?>

Before the version and before the encoding there should be a space.

jkdev's user avatar

jkdev

11.1k15 gold badges55 silver badges77 bronze badges

answered Jul 2, 2019 at 13:30

Michael Fahim's user avatar

Problem is that you are doing something wrong in XML layout file

android:text=" <- Go Back" // this creates error
android:text="Go Back" // correct way

answered Nov 29, 2020 at 7:35

Vijay's user avatar

VijayVijay

1,0858 silver badges22 bronze badges

I am working on an application, with following XML. but whenI try to clean/build my project the following error occurs:

«error: Error parsing XML: not well-formed (invalid token)»

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/hello";
/>
</LinearLayout>

What does it possibly mean?

Sree's user avatar

Sree

3,1162 gold badges31 silver badges39 bronze badges

asked Aug 17, 2011 at 8:19

Usama Sarwar's user avatar

Usama SarwarUsama Sarwar

8,8207 gold badges52 silver badges79 bronze badges

1

I had this problem, and when I had android:text="< Go back" it had the correct syntax highlighting, but then I realized it’s the < symbol that is messing everything up.

answered Jan 23, 2016 at 2:18

Rock Lee's user avatar

3

It means there is a compilation error in your XML file, something that shouldn’t be there: a spelling mistake/a spurious character/an incorrect namespace.

Your issue is you’ve got a semicolon that shouldn’t be there after this line:

  android:text="@string/hello";

answered Aug 17, 2011 at 8:21

Blundell's user avatar

BlundellBlundell

74.5k30 gold badges208 silver badges232 bronze badges

3

I had same problem. you can’t use left < arrow in text property like as android:text="< Go back" in your xml file. Remove any < arrow from you xml code.

Hope It will helps you.

answered Dec 29, 2016 at 6:17

Dalvinder Singh's user avatar

Dalvinder SinghDalvinder Singh

1,0831 gold badge12 silver badges19 bronze badges

1

Verify that you don’t have any spaces or tabs before

<?xml version="1.0" encoding="utf-8"?>

also refresh and clean your project in eclipse.

I get this error every now and then and the above suggestions fix the issue 99% of the time

answered Aug 17, 2011 at 8:23

Julian Suarez's user avatar

Julian SuarezJulian Suarez

4,4994 gold badges24 silver badges40 bronze badges

To solve this issue, I pasted my layout into https://www.xmlvalidation.com/, which told me exactly what the error was. As was the case with other answers, my XML had < in a string.

answered Apr 20, 2018 at 18:00

Alan Kinnaman's user avatar

Remove the semicolon after hello

answered Nov 30, 2013 at 9:12

Vincent Thacker's user avatar

I had the same problem. In my case, even though I have not understood why, the problem was due to & in one of the elements like the following where a and b are two tokens/words:

<s> . . . a & b . . . </s>

and to resolve the issue I turned my element’s text to the following:

<s> . . . a and b . . . </s>

I thought it might be the case for some of you. Generally, to make your life easier, just go and read the character at the index mentioned in the error message (line:..., col:...) and see what the character is.

answered Nov 18, 2019 at 0:10

Pedram's user avatar

PedramPedram

2,3462 gold badges29 silver badges45 bronze badges

In my case I forgot to end my ConstrainLayout

</android.support.constraint.ConstraintLayout>

After that, everything started working correctly.

answered Dec 6, 2018 at 10:18

Wiktor Kalinowski's user avatar

0

I tried everything on my end and ended up with the following.

I had the first line as:

<?xmlversion="1.0"encoding="utf-8"?>

And I was missing two spaces there, and it should be:

<?xml version="1.0" encoding="utf-8"?>

Before the version and before the encoding there should be a space.

jkdev's user avatar

jkdev

11.1k15 gold badges55 silver badges77 bronze badges

answered Jul 2, 2019 at 13:30

Michael Fahim's user avatar

Problem is that you are doing something wrong in XML layout file

android:text=" <- Go Back" // this creates error
android:text="Go Back" // correct way

answered Nov 29, 2020 at 7:35

Vijay's user avatar

VijayVijay

1,0858 silver badges22 bronze badges

Hi I am working on scraping the XML file. For HTML I have used scrapy and for XML I decided to parse it by using xml.sax.

Following is an example code (don’t treat it as a real example) just to view my doubt:

from xml.sax.handler import ContentHandler
import xml.sax

xmlFilePath = 'users/documents/jobstext.xml'

try:
    parser = xml.sax.make_parser( )
    parser.parse(open(xmlFilePath))

except (xml.sax.SAXParseException), e:
        print "*** PARSER error: %s" % e
        print e,"What is the error actually >>>>"  

Following is XML code:

<?xml version="1.0" encoding="utf-8"?>
<jobs>
  <reader><![CDATA[Identity Group]]></reader>
  <readerUrl><![CDATA[http://www.example.com]]></readerUrl>

  <job>
    <title><![CDATA[Architect - OT]]></title>
    <category><![CDATA[LTC/SNF]]></category>
    <jobId><![CDATA[139693]]></jobId>
    <specialization><![CDATA[LTC/SNF]]></specialization>
    <positionType><![CDATA[Travel]]></positionType>
    <description><![CDATA[<DIV>OT&nbsp;needed for a SNF in&nbsp;Oregon.&nbsp; Oregon is a dramatic land of many changes. From the rugged Oregon seacoast, the high mountain passes of the country for Travel Allied Professionals and Travel Nurses. Our clients are among the most prestigious healthcare facilities in the country.</DIV>
<DIV>&nbsp;</DIV>
 </description>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3><SPAN style="FONT-FAMILY: Symbol; COLOR: black; mso-ascii-font-family: 'Times New Roman'">�</SPAN><SPAN style="COLOR: black"><FONT face="Times New Roman"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Position will manage 24 ED Rooms with 24/7 accountability<o:p></o:p></FONT></SPAN></FONT></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3><SPAN style="FONT-FAMILY: Symbol; COLOR: black; mso-ascii-font-family: 'Times New Roman'">�</SPAN><SPAN style="COLOR: black"><FONT face="Times New Roman"> <SPAN style="mso-spacerun: yes">&nbsp;</SPAN>55 FTEs <o:p></o:p></FONT></SPAN></FONT></P>
  </job>
</jobs>

Result:

*** PARSER error: users/documents/jobstext.xml:13:150: not well-formed <invalid token>
users/documents/jobstext.xml:13:150: not well-formed <invalid token> What is the error actually >>>>

What is happening when the execution reaches <p> tag and index 150 its displaying an error invalid token? I am expecting this becuase of ? tag as you can see this in the above error .

So can anyone please let me know how to solve this error of not well-formed <invalid token> in xml parsing,

If I explained in a wrong format, I am sorry, but hope I explained the concept well.

Edited Code:

<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial">THE MOST COMPETITIVE RATES IN NM .....<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial">Busy <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:place w:st="on"><st1:PlaceName w:st="on">Acute</st1:PlaceName> <st1:PlaceName w:st="on">Care</st1:PlaceName> <st1:PlaceType w:st="on">Hospital</st1:PlaceType></st1:place> needs Occupational Therapists.&nbsp; Experience with </SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Ortho, Neuro, vestibular balance, aquatic a plus!<SPAN style="COLOR: black">&nbsp; New grads welcome.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Signon Bonus and help with relocation.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>For more details please call or email Carole 800 995 2673 X1329 or <A href="mailto:cs@coremedicalgroup.com"><SPAN style="mso-bidi-font-weight: bold; mso-bidi-font-size: 12.0pt">cs@coremedicalgroup.com</SPAN></A><o:p></o:p></SPAN></SPAN></P>

I’ve come across another APK that’s suffering from this issue:

Information

Apktool Version: 2.2.2
Operating System: Both Linux and Mac
APK From: https://forum.xda-developers.com/android/apps-games/ps4-remote-play-android-thread-t3068225

Steps to Reproduce

$ apktool d RemotePlayPortV5.1_ITB.apk
...
$ apktool b RemotePlayPortV5.1_ITB

I: Using Apktool 2.2.2 on RemotePlayPortV5.1_ITB.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /root/.local/share/apktool/framework/1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
root@99033f046f3d:/usr/src/apk# apktool b RemotePlayPortV5.1_ITB
I: Using Apktool 2.2.2
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether resources has changed...
I: Building resources...
W: /usr/src/apk/RemotePlayPortV5.1_ITB/res/layout/companionutil_layout_alert_dialog.xml:2: error: Error parsing XML: not well-formed (invalid token)
W:
W: /usr/src/apk/RemotePlayPortV5.1_ITB/res/layout/companionutil_layout_alert_dialog_game2_confirm.xml:2: error: Error parsing XML: not well-formed (invalid token)
W:
W: /usr/src/apk/RemotePlayPortV5.1_ITB/res/layout/companionutil_layout_alert_dialog_game_confirm.xml:2: error: Error parsing XML: not well-formed (invalid token)
W:
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/tmp/brut_util_Jar_4284272564605293496.tmp, p, --forced-package-id, 127, --min-sdk-version, 17, --target-sdk-version, 19, --version-code, 10500, --version-name, 1.5.0, --no-version-vectors, -F, /tmp/APKTOOL6062192940819296925.tmp, -0, arsc, -0, arsc, -I, /root/.local/share/apktool/framework/1.apk, -S, /usr/src/apk/RemotePlayPortV5.1_ITB/res, -M, /usr/src/apk/RemotePlayPortV5.1_ITB/AndroidManifest.xml]
	at brut.androlib.Androlib.buildResourcesFull(Androlib.java:477)
	at brut.androlib.Androlib.buildResources(Androlib.java:411)
	at brut.androlib.Androlib.build(Androlib.java:310)
	at brut.androlib.Androlib.build(Androlib.java:263)
	at brut.apktool.Main.cmdBuild(Main.java:227)
	at brut.apktool.Main.main(Main.java:84)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/tmp/brut_util_Jar_4284272564605293496.tmp, p, --forced-package-id, 127, --min-sdk-version, 17, --target-sdk-version, 19, --version-code, 10500, --version-name, 1.5.0, --no-version-vectors, -F, /tmp/APKTOOL6062192940819296925.tmp, -0, arsc, -0, arsc, -I, /root/.local/share/apktool/framework/1.apk, -S, /usr/src/apk/RemotePlayPortV5.1_ITB/res, -M, /usr/src/apk/RemotePlayPortV5.1_ITB/AndroidManifest.xml]
	at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:440)
	at brut.androlib.Androlib.buildResourcesFull(Androlib.java:463)
	... 5 more
Caused by: brut.common.BrutException: could not exec (exit code = 1): [/tmp/brut_util_Jar_4284272564605293496.tmp, p, --forced-package-id, 127, --min-sdk-version, 17, --target-sdk-version, 19, --version-code, 10500, --version-name, 1.5.0, --no-version-vectors, -F, /tmp/APKTOOL6062192940819296925.tmp, -0, arsc, -0, arsc, -I, /root/.local/share/apktool/framework/1.apk, -S, /usr/src/apk/RemotePlayPortV5.1_ITB/res, -M, /usr/src/apk/RemotePlayPortV5.1_ITB/AndroidManifest.xml]
	at brut.util.OS.exec(OS.java:95)
	at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:434)
	... 6 more

Example invalid .xml:

<?xml version="1.0" encoding="utf-8"?>
<o.ﺗ android:layout_gravity="center" android:orientation="vertical" android:background="@drawable/companionutil_drawable_alert_dialog" android:layout_width="fill_parent" android:layout_height="wrap_content" landscape_marginLeft="33dp" landscape_marginRight="33dp" portrait_marginLeft="11dp" portrait_marginRight="11dp"
  xmlns:android="http://schemas.android.com/apk/res/android">
    <com.playstation.companionutil.CompanionUtilAdjustTextView android:textSize="16.0dip" android:textColor="#ffffffff" android:id="@id/com_playstation_companionutil_id_alert_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="11.0dip" android:layout_marginTop="17.0dip" android:layout_marginRight="11.0dip" android:text="" android:lineSpacingExtra="1.0dip" />
    <com.playstation.companionutil.CompanionUtilAdjustButton android:textSize="16.0dip" android:textColor="#ffffffff" android:id="@id/com_playstation_companionutil_id_alert_positive_button" android:background="@drawable/companionutil_drawable_alert_dialog_button" android:layout_width="fill_parent" android:layout_height="28.0dip" android:layout_marginLeft="11.0dip" android:layout_marginTop="15.0dip" android:layout_marginRight="11.0dip" android:layout_marginBottom="15.0dip" android:text="@string/com_playstation_companionutil_msg_ok" />
</o.ﺗ>

APK

PS4 Remote Play Port
(https://forum.xda-developers.com/android/apps-games/ps4-remote-play-android-thread-t3068225)

Questions to ask before submission

Have you tried apktool d, apktool b without changing anything? Yes
If you are trying to install a modified apk, did you resign it? No
Are you using the latest apktool version? Yes

  • Remove From My Forums
  • Question

  • User386247 posted

    I’m having this issue with 2 of my layouts whenever i try to run my app, this is the code that i have for the first layout

    <include layout="@layout/content_main" />
                                                    -------------------->Error showing in this blank line
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@android:drawable/ic_dialog_email" />
    
    <Button
        android:text="Resgistrar Estudiantes"
        android:layout_width="400px"
        android:layout_height="110px"
        android:layout_marginTop="250px"
        android:layout_marginLeft="180px"
        android:id="@+id/BtnRegEstudiante" />
    

    />

    And this is the one the i have for my second layout

    width=»matchparent»
    android:layoutheight=»matchparent»
    android:columnCount=»2″
    android:rowCount=»6″
    android:id=»@+id/gridLayout1″

    * android:layout_width=»120px» * ———Error showing in this line
    android:layout_height=»100px»
    ad:minWidth=»30px»
    ndroiandroid:minHeight=»30px»
    android:paddingTop=»60px»
    android:paddingLeft=»20px»
    android:text=»Nombre»
    android:textColor=»@android:color/black»
    android:id=»@+id/LblNombre»

    />
    
    <EditText
    android:id="@+id/TxtNombre"
    android:layout_width="285px"
    android:layout_height="100px"
    android:minWidth="30px"
    android:minHeight="30px"
    android:paddingTop="40px"
    android:paddingLeft="20px"
    android:layout_marginLeft="150px"
    />
    

    />

Answers

  • User386247 posted

    I just found the error haha, i was missing a «=»

       <Button
            android:id="@+id/BtnRegEstudiante"
            android:text="Registro de Estudiantes"
            android:layout_width="400px"
            android:layout_height="150px"
            android:layout_marginTop="250px"
            **android:layout_marginLeft="180px"/>**
    
    • Marked as answer by

      Thursday, June 3, 2021 12:00 AM

When loading and saving XML data using FromXml() and ToXml() in C++, the data should be in the local C++ code page. If this is not the case then you may get the error ‘Error — not well-formed (invalid token) at line x’.

This may be resolved by building the application as Unicode, or by using FromXmlStream() and ToXmlStream() which deal with Binary Data and converting the data yourself.

XML Encoding

Xml documents can be encoded using a number of different encodings. The type of encoding is indicated using the encoding tag in the document header (i.e. <?xml version=»1.0″ encoding=»UTF-8″?>).

Writing an XML document to file

When an XML document is persisted as a file, it is safer to consider it in terms as of a stream of bytes as opposed to stream of characters. When an XML document is serialized to a file, an encoding is applied to it. The resulting file will then be correctly encoded given the encoding applied.

  • If a Unicode encoding is applied, the resulting file is prefixed with the Unicode header 0xFF 0xFE, and will be encoded with 2 bytes per character.
  • If a UTF-8 encoding is applied the resulting file will contain a variable number of bytes per character. If this file is then viewed using a tool incapable of decoding UTF-8, then you may see it contains a number of strange characters. If the file is viewed using an UTF-8 compliant application (e.g. IExplorer, Notepad on Win2000 onwards, Visual Studio .Net) then the XML Document will appear with the correct characters (if characters are corrupted or misrepresented, it should be noted that some fonts do not contain the full UNICODE set)

Turning an XML document a string

When an XML document is created from a generated class using ToXml (ToXml returns a string). The string returned is encoded as Unicode (except in C++ non-debug builds), however the XML document header does not show any encoding (<?xml version=»1.0″?>).

The string returned is Unicode, Unicode is the internal character representation for VB6, .Net & Java, as such if it is written to file or passed to another application, it should be passed as Unicode. If it has to be converted to a 1 byte per character representation prior to this, then data will likely be corrupted if complex characters have been used within the document.

If you need to persist an XML document to a file use ToXmlFile, if you need pass an XML document to another (non-Unicode) application, then should use ToXmlStream.

There is also a problem that commonly occurs in C++ UNICODE applications when dealing with UTF-8 encoded data. If you load a UFT-8 encoded file into a UNICODE application, the temptation is to store it in a UNICODE string (WCHAR*), and the conversion to Unicode is often implicit (part of some string/bstr class). However these conversions typically assume the source string is in the local code page, which is rarely UTF-8, and more frequently ANSI. So when the data is converted to UNICODE, the conversion function does not treat the data as UTF-8, and so does not correctly decode it. This results in a UNICODE string which no longer represents the source.

In these circumstances, it is better to either treat the data as binary or to use the appropriate conversion method — utf8 to Unicode.

Passing an XML document to a ASCII or ANSI application

It is common to want to pass the XML document you have created to a non-Unicode application. If you need to do this then you may look first at ToXml, this will provide you with a UNICODE string, however converting this to an ASCII or ANSI string may cause the corruption of complex characters (you lose information going from 2 bytes to 1 byte per character). You could take the string returned from ToXml, and apply your own UTF-8 encoding, however the encoding attribute in the header (<?xml version=»1.0″ encoding=»UTF-8″?>) would not be present, and the XML parser decoding the document may misinterpret it.

The better solution is to use the ToXmlStream method. This allows you to specify an encoding, and returns a stream of bytes (array of bytes in VB). This byte stream is a representation of the XML Document in the given encoding, containing the correct encoding attribute in the header (<?xml version=»1.0″ encoding=»UTF-8″?>).

Article ID: 87, Created: 3/20/2012 at 11:24 AM, Modified: 3/20/2012 at 11:24 AM

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Parsing error using directives with aliases are not allowed people playground
  • Passlib exe unknown hash error hash could not be identified
  • Passive mode ftp error
  • Passive interrupt error
  • Parsing error unexpected token expected react

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии