smart-fun / XmlToJson

Android Library for converting XML to JSON and JSON to XML
Apache License 2.0
557 stars 112 forks source link

Parse android xml views #23

Open ayodelekehinde opened 4 years ago

ayodelekehinde commented 4 years ago

I tired parsing android layout XML, but it didnt maintain hierarchy

smart-fun commented 4 years ago

hi! could you please attach the XML file you tried so that I can have a look? thanks!

ayodelekehinde commented 4 years ago

Try parse this:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">

<TextView
    android:id="@+id/txt_hello"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:text="Hello world" />

      <TextView
    android:id="@+id/txt_hello"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:text="Hello world" />

    <LinearLayout 
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

 <TextView
    android:id="@+id/txt_hello"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:text="Hello world" />

     <TextView
    android:id="@+id/txt_hello"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:text="Hello world" />

    </LinearLayout>

smart-fun commented 4 years ago

Hi,

in xml format there must be 1 root element containing all the others. For example a at the top of the file and at the bottom. Otherwise the xml is not valid.

Arnaud.