Prev: DjangoCon Europe - 24. - 26.5.2010 in Berlin
Next: Constructing an if statement from the client data in python
From: Chaim Krause on 13 Apr 2010 11:26 I am building a web page (HTML 4.01 Transitional) using xml.dom.minidom. I have created a <script> node and I have added the Javascript as a child text node. The issue is that the Javascript includes quotes that I want to survive when I write the XML to a file. The issue for me is that they are translated into ". I know that this is the expected behavior, but I cannot find a manner to override this behavior to have the quotes survive. For example, what I want: var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); What I get: var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); What do you suggest I do to get the desired behavior without rewriting xml.dom? Or is overriding the method the best way to go?
From: Chaim Krause on 13 Apr 2010 11:52 I am looking to find the best answer to my question, but in the mean time I have resorted to monkey patching. def _write_data_no_quote(writer, data): "Writes datachars to writer." data = data.replace("&", "&").replace("<", "<") data = data.replace(">", ">") writer.write(data) minidom._write_data = _write_data_no_quote Maybe this is the best way to do this. I'm not sure.
From: Stefan Behnel on 13 Apr 2010 12:35 Chaim Krause, 13.04.2010 17:26: > I am building a web page (HTML 4.01 Transitional) using > xml.dom.minidom. I have created a<script> node and I have added the > Javascript as a child text node. The issue is that the Javascript > includes quotes that I want to survive when I write the XML to a file. > The issue for me is that they are translated into". You should use an HTML generator tool rather than a generic XML tool like xml.dom.minidom. You need something that knows that the <script> tag contains CDATA content in HTML, and that can serialise in an HTML aware way (self-closing tags, etc.). Check the Python Wiki or PyPI, they have tons of HTML generators. Stefan
From: Chaim Krause on 13 Apr 2010 12:45
Stefan, Thank you. The reason that I am using xml.dom.minidom is that I am restricted to a stock RHEL5 stack. That means 2.4 with nothing added. (Welcome to US Army IT !!!) But, I figured out that I need to back up from xml.dom.minidom to xml.dom and then I can use createCDATASection and get what I need. Now I am off to fix the issue solving this unmasked. (Google Maps API v3 doesn't like to be in an HTML 4.01 Transitional page. Ugh) Thanks |