• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: substring (or) CDATA XML PARSING?!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: substring (or) CDATA XML PARSING?!


  • Subject: Re: substring (or) CDATA XML PARSING?!
  • From: Filip van der Meeren <email@hidden>
  • Date: Fri, 10 Apr 2009 14:44:46 +0200

Hello,

Just use NSScanner (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSScanner_Class/Reference/Reference.html ) to parse those <html> tags.
Something like this should do the job:


NSString *stringBeforeHtml = nil;
NSScanner *scanner = [[NSScanner alloc] initWithString:@"SomeString<html></html>"];
if([scanner scanUpToString:@"<html>" intoString:&stringBeforeHtml]) {
// From here on the left part of the string is located within stringBeforeHtml,
// And the rest is still in the scanner.
// Now you can choose, or you parse the rest with the scanner,
// or you just ask it its scanLocation, and you have the index from where to substring.
}


The code above could be partially incorrect, since I am typing on a computer without XCode.

Filip van der Meeren
email@hidden
http://sourceforge.net/projects/xlinterpreter

On 10 Apr 2009, at 14:31, developers mac wrote:

Hi there,

I went through the various substring methods like
NSString *str1 = [theResponseString substringFromIndex:2]
NSString *pathTrimmed = [theResponseString lastPathComponent];

and also other methods from:

http://developer.apple.com/documenta...cc/cl/NSString<http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/cl/NSString >

But none of them fits my requirement.

My String:

Thisismyentirestringwithhtmltagtowardstheend<html><head><title>My
Page</title></head><body>My web page</body></html>

All I have to do is to get the complete html tag out of that string. Also,
the position of the <HTML> tag will vary from time to time.


Is that possible, can some one post their suggestions/code samples please?

If not, I have to do it other way. I have an xml:

<tag1>
<method>
<id>001</id>
<name>james</name>
<![CDATA[ <html><head><title>My Page</title></head><body>My web
page</body></html> ]]>
</method>
</tag1>

I have to parse the xml & retrieve the CDATA alone. I have written the
parser method, but it fails to read the CDATA alone. It reads the <id>&
<name> tags. Also all the other are inside some other node. But CDATA is not
inside any node. I know that it is the problem. But i cant add a tag to
that.


Is there any way to parse the CDATA & retrieve the XML?

Thanks in Advance!
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: substring (or) CDATA XML PARSING?!
      • From: Filip van der Meeren <email@hidden>
References: 
 >substring (or) CDATA XML PARSING?! (From: developers mac <email@hidden>)

  • Prev by Date: Re: substring (or) CDATA XML PARSING?!
  • Next by Date: Re: substring (or) CDATA XML PARSING?!
  • Previous by thread: Re: substring (or) CDATA XML PARSING?!
  • Next by thread: Re: substring (or) CDATA XML PARSING?!
  • Index(es):
    • Date
    • Thread