앞에 오는 0이있는 문자열이 포함 된 XML 문서가 있습니다. XmlResourceParser를 사용하여 XML 파일을 반복 할 때 getAttributeValue를 호출 할 때 선행 0이있는 문자열이 맨 앞의 0을 제거하도록 수정되었음을 알았습니다. 이 기능은 과거에 작동했으며 Android Studio 3.x로 업그레이드 한 후에 만 눈치 챘습니다. "getAttributeValue"가 선행 0을 보존하기 위해해야 할 특별한 것이 있습니까?안드로이드의 XMLPullParser getAttributeValue가 문자열에서 선행 0을 제거합니다.
다음<?xml version="1.0" encoding="UTF-8"?>
<FictionalSpies>
<Property Country="Great Britain" Agency="MI6">
<Item FullName="James Bond" AgentCode="007" />
<Item FullName="John Wolfgramm" AgentCode="0010" />
<Item FullName="Sam Johnston" AgentCode="0012" />
</Property>
<Property Country="United States" Agency="CONTROL">
<Item FullName="Maxwell Smart" AgentCode="86" />
<Item FullName="Unknown" AgentCode="99" />
<Item FullName="The Chief" AgentCode="Q" />
</Property>
<Property Country="United States" Agency="MiB">
<Item FullName="James Darrell Edwards III" AgentCode="J" />
<Item FullName="Kevin Brown" AgentCode="K" />
<Item FullName="Derrick Cunningham" AgentCode="D" />
</Property>
</FictionalSpies>
이 목록의 각 '스파이'의 로그 인쇄 밖으로 : 여기
내가 사용하고 테스트 XML 파일입니다. 보시다시피 처음 세 사람은 AgentCode에서 "00"을 잃어 버렸습니다. 예를 들어 James Bond는 상담원 코드가 "007"이고 "7"이 아니어야합니다. 여기D/XMLTest: Great Britain MI6 James Bond 7
D/XMLTest: Great Britain MI6 John Wolfgramm 10
D/XMLTest: Great Britain MI6 Sam Johnston 12
D/XMLTest: United States CONTROL Maxwell Smart 86
D/XMLTest: United States CONTROL Unknown 99
D/XMLTest: United States CONTROL The Chief Q
D/XMLTest: United States MiB James Darrell Edwards III J
D/XMLTest: United States MiB Kevin Brown K
D/XMLTest: United States MiB Derrick Cunningham D
폼에 버튼을 눌러에 매여와 XML 생성 이전의 로그 메시지 반복 처리되는 코드입니다 :
public void buttonOnClick(View v)
{
int eventType = -1;
String name;
String country = null;
String agency = null;
String fullName = null;
String agentCode = null;
try
{
XmlResourceParser xmlRP = getResources().getXml(R.xml.test);
while (eventType != XmlResourceParser.END_DOCUMENT)
{
if (eventType == XmlResourceParser.START_TAG)
{
name = xmlRP.getName();
if (name.contentEquals("Property"))
{
country = xmlRP.getAttributeValue(null, "Country");
agency = xmlRP.getAttributeValue(null, "Agency");
} else if (name.contentEquals("Item"))
{
fullName = xmlRP.getAttributeValue(null, "FullName");
agentCode = xmlRP.getAttributeValue(null, "AgentCode");
Log.d("XMLTest", country + " " + agency + " " + fullName + " " + agentCode);
}
}
eventType = xmlRP.next();
}
} catch (XmlPullParserException e)
{
} catch (IOException e)
{
}
}
실제로 처리하는 동안 스트립하는 새로운 aapt 버전이라고 생각합니다. 'getAttributeValue()'는 문자열에있는 모든 값을 맹목적으로 반환합니다. aapt2를 일시적으로 사용 중지하여 테스트 할 수 있습니다 (https://stackoverflow.com/a/46988209). –
감사합니다 마이크, 그게 해결 됐어! – steve
수정보다는 임시 해결 방법과 더 비슷합니다. 확실히 aapt2의 버그처럼 보입니다. 나는 나중에 시간이있을 때 그것을 조사해야 할 것입니다. 다행히도 지금 당장은 나중에 작업 할 수 있습니다. –