Re: NSXMLDocument question
Re: NSXMLDocument question
- Subject: Re: NSXMLDocument question
- From: John Stiles <email@hidden>
- Date: Thu, 2 Mar 2006 10:14:28 -0800
Save your .m file with encoding UTF8, and use [NSString
stringWithUTF8String:"your Unicode characters go here"];
As the warning says, @"whatever" only works with ASCII. This is well
documented and very well covered in the archives, although some
posters have gotten it wrong at times (heck, I've seen Radar replies
which imply that some Apple guys don't know the rule :) )
On Mar 2, 2006, at 9:36 AM, malcom wrote:
Hi again. I tried to work with XML classes by Apple. All seems to
works pretty well (but I need to try XSL yet) but I've a problem.
This is my code:
NSXMLElement *rootArticle = (NSXMLElement *)[NSXMLNode
elementWithName:@"ARTICLE"];
NSXMLDocument *xmlDoc = [[NSXMLDocument alloc]
initWithRootElement:rootArticle];
[xmlDoc setVersion:@"1.0"];
[xmlDoc setCharacterEncoding:@"UTF-8"];
NSXMLElement *rootHeaders = (NSXMLElement *)[NSXMLNode
elementWithName:@"HEADER"];
NSXMLElement *rootText = (NSXMLElement *)[NSXMLNode
elementWithName:@"CONTENTS"];
[rootArticle addChild: rootHeaders];
[rootArticle addChild: rootText];
NSXMLNode *node = [[NSXMLNode alloc] initWithKind:NSXMLTextKind
options:NSXMLNodePreserveAll];
[node setName:@"TAG_SUBJECT"];
[node setStringValue: @"these are strange chars: è à ò"];
[rootHeaders addChild: node];
// writing
NSData *xmlData = [xmlDoc XMLDataWithOptions:NSXMLDocumentTidyHTML];
if (![xmlData writeToFile:@"/Users/malcom/Desktop/xmldata_yeah.xml"
atomically:YES]) {
NSBeep();
NSLog(@"Could not write document out...");
return NO;
}
When I try to set this [node setStringValue: @"these are strange
chars: è à ò"]; I receive a warning: non-ASCII character in CFString
literal. In fact when the xml was written to a file the results are
incomprensible chars (something like this √(r)) and the final result
was wrong.
How can I store these chars in NSString and then to an XML file? Where
I'm wrong with the code?
On 3/2/06, John Stiles <email@hidden> wrote:
I wouldn't rely on Safari's XSLT capabilities yet. We tried using it
recently and had to abandon the plan entirely because it corrupts any
non-ASCII characters. So our USA page rendered great, but our Korean
page turned to gibberish. We have a radar open; I'd suggest anyone
else
who would be affected by this should do the same.
There is a command-line XSLT engine that you can use which seemed to
work great; I haven't tried NSXMLDocument's methods so I don't
know if
they produce correct results.
Robert Walker wrote:
It sounds to me like you may be able to benefit from NSXMLDocument's
"built-in" support for XSLT processing.
Have you looked at:
NSXMLDocument:
- (id)objectByApplyingXSLT:(NSData *)xslt arguments:(NSDictionary
*)arguments error:(NSError **)error
or
- (id)objectByApplyingXSLTAtURL:(NSURL *)xsltURL
arguments:(NSDictionary *)arguments error:(NSError **)error
On Mar 2, 2006, at 8:40 AM, Ilan Volow wrote:
Off the top-of-my-head, I'd say what you should do would be to call
NSXMLNode's processingInstructionWithName:stringValue method to get
yourself a processing instruction node, and then add this node to
your NSXMLDocument.
-- Ilan
On Mar 2, 2006, at 7:13 AM, malcom wrote:
Hello, I need to generate an XML Document from some NSString.
Then,
the xml string will be transmitted to an XSLT document and
finally it
will be rendered by WebKit.
But I have a problem...
NSXMLDocument can generate a document like this:
<?xml version="1.0" encoding="utf-8"?>
<ROOT KEY>
..
..
But I need to put this string:
<?xml-stylesheet type="text/xsl" href="template.xsl" ?>
after the first line and pass all to browser. How can I add it? Is
possible?
I have found this on ADC:
file:///Developer/ADC Reference Library/documentation/Cocoa/
Conceptual/NSXML_Concepts/Articles/WritingXML.html#//apple_ref/
doc/uid/TP40001256
"...NSXML includes support for XSLT. With XSLT you can apply a
set of
template rules and patterns to a source XML document and thereby
transform that document into another XML document or into an HTML,
RTF, or plain-text document. Two NSXMLDocument methods are the
interface to XSLT processing:
- (id)objectByApplyingXSLT:(NSString *)xslt error:(NSError **)
error
- (id)objectByApplyingXSLTAtURL:(NSURL *)xsltURL error:(NSError
**)error"
Is this a better way to do it?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40clarux.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40mac.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40blizzard.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gmail.com
This email sent to email@hidden
--
www.malcom-mac.com
mac/win software development
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40blizzard.com
This email sent to email@hidden
_______________________________________________
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