Just An Application

September 24, 2011

Android Internals: Binary XML – Part Five: The XML Start And End Namespace Chunks

1.0 The Example

The example contains a single pair of Start/End Namespace chunks

    0000000 03 00 08 00 c4 02 00 00 01 00 1c 00 84 01 00 00
    0000010 0a 00 00 00 00 00 00 00 00 00 00 00 44 00 00 00
    0000020 00 00 00 00 00 00 00 00 1a 00 00 00 36 00 00 00
    0000030 54 00 00 00 60 00 00 00 72 00 00 00 ca 00 00 00
    0000040 ce 00 00 00 ea 00 00 00 fe 00 00 00 0b 00 6f 00
    0000050 72 00 69 00 65 00 6e 00 74 00 61 00 74 00 69 00
    0000060 6f 00 6e 00 00 00 0c 00 6c 00 61 00 79 00 6f 00
    0000070 75 00 74 00 5f 00 77 00 69 00 64 00 74 00 68 00
    0000080 00 00 0d 00 6c 00 61 00 79 00 6f 00 75 00 74 00
    0000090 5f 00 68 00 65 00 69 00 67 00 68 00 74 00 00 00
    00000a0 04 00 74 00 65 00 78 00 74 00 00 00 07 00 61 00
    00000b0 6e 00 64 00 72 00 6f 00 69 00 64 00 00 00 2a 00
    00000c0 68 00 74 00 74 00 70 00 3a 00 2f 00 2f 00 73 00
    00000d0 63 00 68 00 65 00 6d 00 61 00 73 00 2e 00 61 00
    00000e0 6e 00 64 00 72 00 6f 00 69 00 64 00 2e 00 63 00
    00000f0 6f 00 6d 00 2f 00 61 00 70 00 6b 00 2f 00 72 00
    0000100 65 00 73 00 2f 00 61 00 6e 00 64 00 72 00 6f 00
    0000110 69 00 64 00 00 00 00 00 00 00 0c 00 4c 00 69 00
    0000120 6e 00 65 00 61 00 72 00 4c 00 61 00 79 00 6f 00
    0000130 75 00 74 00 00 00 08 00 54 00 65 00 78 00 74 00
    0000140 56 00 69 00 65 00 77 00 00 00 1e 00 48 00 65 00
    0000150 6c 00 6c 00 6f 00 20 00 57 00 6f 00 72 00 6c 00
    0000160 64 00 2c 00 20 00 50 00 65 00 6e 00 64 00 72 00
    0000170 61 00 67 00 6f 00 6e 00 41 00 63 00 74 00 69 00
    0000180 76 00 69 00 74 00 79 00 00 00 00 00 80 01 08 00
    0000190 18 00 00 00 c4 00 01 01 f4 00 01 01 f5 00 01 01
    00001a0 4f 01 01 01 00 01 10 00 18 00 00 00 02 00 00 00
    00001b0 ff ff ff ff 04 00 00 00 05 00 00 00 02 01 10 00
    00001c0 60 00 00 00 02 00 00 00 ff ff ff ff ff ff ff ff
    00001d0 07 00 00 00 14 00 14 00 03 00 00 00 00 00 00 00
    00001e0 05 00 00 00 00 00 00 00 ff ff ff ff 08 00 00 10
    00001f0 01 00 00 00 05 00 00 00 01 00 00 00 ff ff ff ff
    0000200 08 00 00 10 ff ff ff ff 05 00 00 00 02 00 00 00
    0000210 ff ff ff ff 08 00 00 10 ff ff ff ff 02 01 10 00
    0000220 60 00 00 00 07 00 00 00 ff ff ff ff ff ff ff ff
    0000230 08 00 00 00 14 00 14 00 03 00 00 00 00 00 00 00
    0000240 05 00 00 00 01 00 00 00 ff ff ff ff 08 00 00 10
    0000250 ff ff ff ff 05 00 00 00 02 00 00 00 ff ff ff ff
    0000260 08 00 00 10 fe ff ff ff 05 00 00 00 03 00 00 00
    0000270 09 00 00 00 08 00 00 03 09 00 00 00 03 01 10 00
    0000280 18 00 00 00 0b 00 00 00 ff ff ff ff ff ff ff ff
    0000290 08 00 00 00 03 01 10 00 18 00 00 00 0c 00 00 00
    00002a0 ff ff ff ff ff ff ff ff 07 00 00 00 01 01 10 00
    00002b0 18 00 00 00 0c 00 00 00 ff ff ff ff 04 00 00 00
    00002c0 05 00 00 00                                    
    00002c4

The bytes in blue are the chunk headers and those in green the chunk bodies.

The Start Namespace chunk starts at 00001a4 and the End Namespace chunk at 00002ac.

2.0 Start And End Namespace Chunks

Start and end namespace chunks represent the scope of a namespace declaration which occurs in the start tag of an element.

If there are multiple declarations in the same start tag then the start namespace chunks for the namespaces appear in the order of the declarations and the end namespace chunks in reverse order.

The chunks which represent the start and end of namespace scopes have the same structure.

3.0 Chunk Header

The chunk header is an instance of the struct ResXMLTree_node.

The header.type field is

The header.headerSize is always 16 (0x0010).

The header.size is always 24 (0x0018).

4.0 Chunk Body

The chunk body is an instance of the following C++ struct (see frameworks/base/include/ResourceTypes.h lines 533-540)

    struct ResXMLTree_namespaceExt
    {
        // The prefix of the namespace.
        struct ResStringPool_ref prefix;
    
        // The URI of the namespace.
        struct ResStringPool_ref uri;
    };

4.1 prefix

The prefix field specifies the XML Namespace prefix as an index into the StringPool of the containing XML chunk.

4.1 uri

The uri field specifies the XML Namespace URI as an index into the StringPool of the containing XML chunk.

5.0 The Example Annotated

5.1 The Start Namespace Chunk

This is an annotated version of the Start Namespace chunk from the example.

    ...

    000001a4 00 01       // type [XML_START_NAMESPACE]
    000001a6 10 00       // header size
    000001a8 18 00 00 00 // chunk size
    --------------------

    000001ac 02 00 00 00 // lineNumber
    000001b0 ff ff ff ff // comment
    ++++++++++++++++++++

    000001b4 04 00 00 00 // prefix
    000001b8 05 00 00 00 // uri
    ==================== [End of XML_START_NAMESPACE]
	
    ...

5.2 The End Namespace Chunk

This is an annotated version of the End Namespace chunk from the example.

    ...

    000002ac 01 01       // type [XML_END_NAMESPACE]
    000002ae 10 00       // header size
    000002b0 18 00 00 00 // chunk size
    --------------------

    000002b4 0c 00 00 00 // lineNumber
    000002b8 ff ff ff ff // comment
    ++++++++++++++++++++

    000002bc 04 00 00 00 // prefix
    000002c0 05 00 00 00 // uri
    ==================== [End of XML_END_NAMESPACE]
	
    ...

Copyright (c) 2011 By Simon Lewis. All Rights Reserved.

Advertisements

Create a free website or blog at WordPress.com.

%d bloggers like this: