OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 | 6 |
7 from grit.format.policy_templates.writers import template_writer | 7 from grit.format.policy_templates.writers import template_writer |
8 | 8 |
9 | 9 |
10 class XMLFormattedWriter(template_writer.TemplateWriter): | 10 class XMLFormattedWriter(template_writer.TemplateWriter): |
(...skipping 13 matching lines...) Expand all Loading... |
24 text: Text content for the new element. | 24 text: Text content for the new element. |
25 | 25 |
26 Returns: | 26 Returns: |
27 The created new element. | 27 The created new element. |
28 ''' | 28 ''' |
29 if attrs == None: | 29 if attrs == None: |
30 attrs = {} | 30 attrs = {} |
31 | 31 |
32 doc = parent.ownerDocument | 32 doc = parent.ownerDocument |
33 element = doc.createElement(name) | 33 element = doc.createElement(name) |
34 for key, value in attrs.iteritems(): | 34 for key, value in sorted(attrs.iteritems()): |
35 element.setAttribute(key, value) | 35 element.setAttribute(key, value) |
36 if text: | 36 if text: |
37 element.appendChild(doc.createTextNode(text)) | 37 element.appendChild(doc.createTextNode(text)) |
38 parent.appendChild(element) | 38 parent.appendChild(element) |
39 return element | 39 return element |
40 | 40 |
41 def AddText(self, parent, text): | 41 def AddText(self, parent, text): |
42 '''Adds text to a parent node. | 42 '''Adds text to a parent node. |
43 ''' | 43 ''' |
44 doc = parent.ownerDocument | 44 doc = parent.ownerDocument |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 # printing. | 82 # printing. |
83 indent = indent[2:] | 83 indent = indent[2:] |
84 lines[i] = indent + '<' + line + '>' | 84 lines[i] = indent + '<' + line + '>' |
85 if (line[0] not in ['/', '?', '!'] and '</' not in line and | 85 if (line[0] not in ['/', '?', '!'] and '</' not in line and |
86 line[len(line) - 1] != '/'): | 86 line[len(line) - 1] != '/'): |
87 # If the current line starts with an opening tag and does not conatin a | 87 # If the current line starts with an opening tag and does not conatin a |
88 # closing tag, increase indent after the line is printed. | 88 # closing tag, increase indent after the line is printed. |
89 indent += ' ' | 89 indent += ' ' |
90 # Reconstruct XML text from the lines. | 90 # Reconstruct XML text from the lines. |
91 return '\n'.join(lines) | 91 return '\n'.join(lines) |
OLD | NEW |