Preserving whitespace when creating NSXMLDocument
Preserving whitespace when creating NSXMLDocument
- Subject: Preserving whitespace when creating NSXMLDocument
- From: Glen Simmons <email@hidden>
- Date: Tue, 25 Apr 2006 12:28:35 -0500
I'm having trouble getting whitespace to be retained when creating an
NSXMLDocument. The setup is that I have an NSTextView subclass to
which the user can add most anything. I need to get the contents of
that view as XHTML and then massage it further. I'm using -
[NSAttributedString dataFromRange:documentAttributes:error:] to get
the XHTML, and then using that to create an NSXMLDocument so I can
iterate through the nodes and fiddle with them.
This works fine except for two conflicting situations:
1. If there are spaces in the text that have a different font, the
XHTML ends up with <font> elements whose string value is just a
space. If I don't pass NSXMLNodePreserveWhitespace, the spaces
disappear. (This situation occurs when using other inputs, like
Arabic-QWERTY. Try it in TextEdit.)
2. From some input, like copy / paste from a web page, I get an error
about "Opening and ending tag mismatch" when trying to create the
NSXMLDocument unless I pass NSXMLDocumentTidyXML.
The real problem is that if I pass both of these, the whitespace is
not preserved. I've tried inserting xmlns:space=”preserve” in the
html tag, since the docs claim that this will cause
NSXMLDocumentTidyXML to preserve whitespace, but this doesn't appear
to be the case. How can I preserve whitespace while also avoiding the
failure case in #2?
Thanks,
Glen Simmons _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden