将HTML代码呈现为文本

时间:2016-03-01 20:20:23

标签: html

我必须制作HTML教程。我需要在页面中显示html代码示例。所以,我希望代码显示如下:

 <h1>hi</h1>

不喜欢这个

hi

有没有标签可以做到这一点?或者我怎么才能用HTML做到这一点?

1 个答案:

答案 0 :(得分:2)

您可以对字符进行编码,以使其在实际页面上显示。对于代码,请使用&gt;制作&lt;并<h1>&lt;h1&gt;text&lt;/h1&gt;</h1>制作&gt;。

<schedule module_id="0" tab_id="0" mobile_row="1" mobile_zipped="1" row="0" section="0">
<daily_prog>
<ep_name data="Serialname1"/>
<ep_time data="11:00PM"/>
<ep_airtime data="Daily"/>
<ep_detail data="Bla Bla Bla About Some Name 1."/>
<ep_image data="prog4ar.jpg"/>
</daily_prog>
<daily_prog>
<ep_name data="Serialname2"/>
<ep_time data="12:00PM"/>
<ep_airtime data="Sunday"/>
<ep_detail data="Bla Bla Bla About Some Name 2 "/>
<ep_image data="prog3.jpg"/>
</daily_prog>
<daily_prog>
<ep_name data="Serialname3"/>
<ep_time data="13:00PM"/>
<ep_airtime data="Monday"/>
<ep_detail data="Bla Bla Bla About Some Name 3 "/>
<ep_image data="prog4.jpg"/>
</daily_prog>
<daily_prog>
<ep_name data="Serialname4"/>
<ep_time data="14:00PM"/>
<ep_airtime data="Daily"/>
<ep_detail data="Bla Bla Bla About Some Name 4 "/>
<ep_image data="prog2.jpg"/>
</daily_prog>


this is the .h file 
@property (nonatomic,strong) NSMutableArray *marrXMLData;
@property (nonatomic,strong) NSMutableString *mstrXMLString;
@property (nonatomic,strong) NSMutableDictionary *mdictXMLPart;

@property (nonatomic,strong) NSMutableArray *months;
@property (nonatomic,strong) NSMutableString *monthName;
@property (nonatomic,strong) NSMutableDictionary *item;


this is my code in .m file



    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict;
    {
        if ([elementName isEqualToString:@"schedule"]) {
            marrXMLData = [[NSMutableArray alloc] init];
        }
        if ([elementName isEqualToString:@"ep_name"]) {
            mdictXMLPart = [[NSMutableDictionary alloc] init];
            item = [[NSMutableDictionary alloc] init];
            NSString *tempStr1 = [attributeDict objectForKey:@"data"];
            [mdictXMLPart setObject:tempStr1 forKey:elementName];
        }
        if ([elementName isEqualToString:@"ep_time"]) {
            NSString *tempStr1 = [attributeDict objectForKey:@"data"];
            [mdictXMLPart setObject:tempStr1 forKey:elementName];
        }
        if ([elementName isEqualToString:@"ep_airtime"]) {

            NSString *tempStr1 = [attributeDict objectForKey:@"data"];
            [mdictXMLPart setObject:tempStr1 forKey:elementName];
            [item setObject:tempStr1 forKey:elementName];
            monthName = [[NSMutableString alloc] initWithString:[attributeDict valueForKey:@"data"]];
        }
        if ([elementName isEqualToString:@"ep_detail"]) {
            NSString *tempStr1 = [attributeDict objectForKey:@"data"];
            [mdictXMLPart setObject:tempStr1 forKey:elementName];
        }
        if ([elementName isEqualToString:@"ep_image"]) {
            NSString *tempStr1 = [attributeDict objectForKey:@"data"];
            [mdictXMLPart setObject:tempStr1 forKey:elementName];
        }
    }

    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;
    {
        [mstrXMLString appendString:string];
        [monthName appendString:string];
    }

    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName;
    {

        if ([elementName isEqualToString:@"ep_name"]) {
            [marrXMLData addObject:mdictXMLPart];
        }

        if ([elementName isEqualToString:@"ep_airtime"]) {

            [item setObject:monthName forKey:@"data"];
            [months addObject:[item copy]];
            NSOrderedSet *mySet = [[NSOrderedSet alloc] initWithArray:months];
            months = [[NSMutableArray alloc] initWithArray:[mySet array]];

          }
        monthName = nil;
        mstrXMLString = nil;
    }

    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
    {
        return [[months valueForKey:@"ep_airtime"] objectAtIndex:section];
    }

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        NSUInteger sections = [[months valueForKey:@"ep_airtime"] count];
        return sections;
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return [[marrXMLData valueForKey:@"ep_airtime"] count];
    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {

        static NSString* const keyToSortBy = @"ep_airtime";
        NSArray * sortedArray = [marrXMLData sortedArrayUsingComparator:^(id obj1, id obj2) {
            NSString *s1 = [obj1 objectForKey:keyToSortBy];
            NSString *s2 = [obj2 objectForKey:keyToSortBy];
            return [s1 caseInsensitiveCompare:s2];
        }];

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
        NSString *showName = [[sortedArray objectAtIndex:indexPath.row] valueForKey:@"ep_airtime"];
        NSString *showTime = [[sortedArray objectAtIndex:indexPath.row] valueForKey:@"ep_time"];

        cell.textLabel.text = showName;
        cell.detailTextLabel.text = showTime ;
        return cell;
    }

在下面的链接中编写HTML时,您可以看到更多方法来更改各种字符。 http://www.escapecodes.info/