Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6215947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:08:51+00:00 2026-05-24T07:08:51+00:00

I always thought that newlines and whitespace in XML documents were ignored ? Is

  • 0

I always thought that newlines and whitespace in XML documents were ignored ? Is that a misconception, or is there something lacking in my code?

What happens is the following: I’m parsing an XML document which I retrieve from my server. This works fine when all content is on 1 line, but fails when the XML document is indented.

My code :

public class JsonTestActivity extends ListActivity {
    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);

       Log.d("xxx", "on create started");
        try {
            URL url = new URL("http://www.morefast.be/gethistory.php");

            HttpURLConnection urlConnection=(HttpURLConnection) url.openConnection();
            urlConnection.setRequestMethod("GET");
            urlConnection.setDoOutput(true);
            urlConnection.setDoInput(true);
            urlConnection.connect();

            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.parse(urlConnection.getInputStream());        

            String path = doc.getElementsByTagName("GeometryCollection").item(0).getFirstChild().getFirstChild().getFirstChild().getNodeValue() ;

            Log.d("xxx", "path is "+path);

        }
        catch (Exception e) {
            Log.d("xxx", e.getMessage());

        }



    }



}

Works fine when the XML file is

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0"><Document>
<GeometryCollection><LineString><coordinates>These are the coordinates</coordinates></LineString></GeometryCollection>
</Document></kml>

But fails when the file is (e.g.)

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0"><Document>
<GeometryCollection>
<LineString><coordinates>These are the coordinates</coordinates></LineString></GeometryCollection>
</Document></kml>

All I changed in those files is adding an extra newline after “GeometryCollection”

LogCat shows

07-30 20:44:48.364: ERROR/AndroidRuntime(545): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mydomain.jsontest/com.mydomain.jsontest.JsonTestActivity}: java.lang.NullPointerException: println needs a message
07-30 20:44:48.364: ERROR/AndroidRuntime(545):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-30 20:44:48.364: ERROR/AndroidRuntime(545):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-30 20:44:48.364: ERROR/AndroidRuntime(545):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-30 20:44:48.364: ERROR/AndroidRuntime(545):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-30 20:44:48.364: ERROR/AndroidRuntime(545):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-30 20:44:48.364: ERROR/AndroidRuntime(545):     at android.os.Looper.loop(Looper.java:123)
07-30 20:44:48.364: ERROR/AndroidRuntime(545):     at android.app.ActivityThread.main(ActivityThread.java:4627)
07-30 20:44:48.364: ERROR/AndroidRuntime(545):     at java.lang.reflect.Method.invokeNative(Native Method)
07-30 20:44:48.364: ERROR/AndroidRuntime(545):     at java.lang.reflect.Method.invoke(Method.java:521)
07-30 20:44:48.364: ERROR/AndroidRuntime(545):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-30 20:44:48.364: ERROR/AndroidRuntime(545):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-30 20:44:48.364: ERROR/AndroidRuntime(545):     at dalvik.system.NativeStart.main(Native Method)
07-30 20:44:48.364: ERROR/AndroidRuntime(545): Caused by: java.lang.NullPointerException: println needs a message
07-30 20:44:48.364: ERROR/AndroidRuntime(545):     at android.util.Log.println_native(Native Method)
07-30 20:44:48.364: ERROR/AndroidRuntime(545):     at android.util.Log.d(Log.java:122)
07-30 20:44:48.364: ERROR/AndroidRuntime(545):     at com.mydomain.jsontest.JsonTestActivity.onCreate(JsonTestActivity.java:43)
07-30 20:44:48.364: ERROR/AndroidRuntime(545):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-30 20:44:48.364: ERROR/AndroidRuntime(545):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-30 20:44:48.364: ERROR/AndroidRuntime(545):     ... 11 more

Is that expected? I’d thought that XML documents ignored whitespace?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:08:51+00:00Added an answer on May 24, 2026 at 7:08 am

    Disclaimer: I don’t do Android (or even Java these days) programming, however…


    White-space in XML is generally not ignored by the parser. Rather it is turned into text nodes (containing the white-space as content). The exact details depends on the XML parser and options
    supplied.

    Could this be changing what getFirstChild() is doing? That is, is the first child of GeometryCollection a text node and not LineString? (And the first child of a text node is …? Kaboom! Although, I can’t fit this into the trace: java.lang.NullPointerException: println needs a message… which seems odd sitting there.)

    I would suggest starting with a better selector and avoiding the manual stepping, if this is indeed the case.

    Happy coding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I always thought that following code std::map<int, int> test; std::cout << test[0] << std::endl;
I always thought that if you didn't implement a heartbeat, there was no way
I always thought that parentheses improved readability, but in my textbook there is a
As as human I always thought that lookup in something sorted is the way
I've always thought that Python's advantages are code readibility and development speed, but time
I've always thought that server-side code is unaffected by the browser requesting it, but
I have code like this: setTimeout(foo, 600); I always thought that foo didn't take
I always thought base.Something was equivalent to ((Parent)this).Something , but apparently that's not the
I always thought that when you dropped a control onto an .aspx page that
I always thought that internal class has access to all data in its external

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.