현재 안드로이드 스튜디오에서 생성된 레이아웃 xml(예를들어 res/layout의 content_main.xml)파일을 파싱하려 합니다.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/textView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_below="@+id/textView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="47dp" />
위와 같은경우에는 Button 안에 layout_width는 wrap_parent 이다.
이런형식의 데이터를 파싱하려합니다.
처음에는 XMLPullParser를 사용해서 파싱을 하였는데요.
문제점이 ""(큰따옴표)안에 데이터가 스트링형식이 아닌 define 되어있는 값으로 나옵니다(텍스트는 스트링으로 잘나오고요)
예를 들어서
android:id="@+id/button" 부분에서 파싱이되면(getAttribute 로 id 를 얻고, getAttributeValue로 그 값을 얻었습니다)
id 가 나오고 @+id/button이 나올줄알았지만, @2055598 처럼 특정 값이 나오고요(이 아이디를 다른곳에서 불러도 같은 @2055598 값이 나옵니다. 마치 define되어있는 값처럼요)
android:layout_height="wrap_content"이부분은 layout_height가 나오고 wrap_content가 아닌 -2값이 출력이 됩니다.
이문제를 해결하는 방법이나 혹시 다른 방법으로 레이아웃을 파싱하는 방법을 좀 알려주시면 감사하겠습니다.