blob: 63536b22b6bda0573c67c9fa698ffc3199d51ba8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
from defs import *
from reader import AXMLReader
from parser import AXMLParser
class AndroidManifest():
def __init__(self, data):
self._buffer = ""
reader = AXMLReader(data)
parser = AXMLParser(reader)
has_ns = False
empty = False
while 1 :
tag = parser.next()
if tag == START_DOCUMENT :
self._buffer += '<?xml version="1.0" encoding="utf-8"?>\n'
elif tag == START_TAG:
if empty:
self._buffer += '>\n'
self._buffer += ' ' * (parser._namespaces.getDepth() - 2)
self._buffer += "<%s%s" % (parser.getTagPrefix(), parser.getTagName())
if not has_ns:
self._buffer += ' xmlns:%s="%s"' % (parser.getNamespacePrefix(0), parser.getNamespaceUri(0))
has_ns = True
for i in range(0, parser.countAttributes()):
self._buffer += ' %s%s="%s"' % (parser.getAttribPrefix(i), parser.getAttribName(i), parser.getAttribValue(i))
empty = True
elif tag == END_TAG:
if empty:
self._buffer += '/>\n'
empty = False
else:
self._buffer += ' ' * (parser._namespaces.getDepth() - 2)
self._buffer += "</%s%s>\n" % (parser.getTagPrefix(), parser.getTagName())
elif tag == TEXT:
if empty:
self._buffer += '>\n'
empty = False
self._buffer += ' ' * (parser._namespaces.getDepth() - 1)
self._buffer += "%s\n" % parser.getText()
elif tag == END_DOCUMENT :
break
else:
break
def getXML(self):
"""Provide the XML content."""
return self._buffer
|