总的来说,AXML是以一个个的node组织在一块的,AXMLPrinter的code中称为trunk。
我们来看AXMLPrinter中的相关code:
chunkType=m_reader.readInt();
// Common header.
m_chunkSize = m_reader.readInt();
int lineNumber=m_reader.readInt();
/*0xFFFFFFFF*/m_reader.skipInt();
这4个字段实际上对应到Android源码中的ResXMLTree_node结构:
struct ResXMLTree_node
{
struct ResChunk_header header;
// Line number in original source file atwhich this element appeared.
uint32_t lineNumber;
// Optional XML comment that was associatedwith this element; -1 if none.
struct ResStringPool_ref comment;
};
struct ResChunk_header
{
// Type identifier for this chunk. The meaning of this value depends
// on the containing chunk.
uint16_t type;
// Size of the chunk header (in bytes). Adding this value to
// the address of the chunk allows you to find its associated data
// (if any).
uint16_t headerSize;
// Total size of this chunk (in bytes). This is the chunkSize plus
// the size of any data associated with the chunk. Adding this value
// to the chunk allows you to completely skip its contents (including
// any child chunks). If this value is the same as chunkSize, there is
// no data associated with the chunk.
uint32_t size;
};
可以看到,这里的解析跟源码还略有差异,AXMLPrinter将CHUNK_XML_START_TAG定义为0x100102,实际上,该tag是一个16位的整形0x0102,只是因为headerSize固定为16字节,即0x0010,所以AXMLPrinter的实现才没问题。