XmlToJson icon indicating copy to clipboard operation
XmlToJson copied to clipboard

Parse android xml views

Open ayodelekehinde opened this issue 4 years ago • 3 comments

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

ayodelekehinde avatar May 05 '20 13:05 ayodelekehinde

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

smart-fun avatar May 05 '20 19:05 smart-fun

Try parse this:

<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>

	

ayodelekehinde avatar May 06 '20 00:05 ayodelekehinde

Hi,

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

Arnaud.

smart-fun avatar May 06 '20 15:05 smart-fun