Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9234277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:45:09+00:00 2026-06-18T06:45:09+00:00

This is my XML: <?xml version=1.0 encoding=UTF-8?> <Tests> <Test case=1> <str>200000</str> </Test> <Test case=2>

  • 0

This is my XML:

<?xml version="1.0" encoding="UTF-8"?>
<Tests>
    <Test case="1">
        <str>200000</str>
    </Test>
    <Test case="2">
        <str>200thousand</str>
    </Test>
    <Test case="3">
        <str>共20萬</str>
    </Test>
    <Test case="4">
        <str>20萬</str>
    </Test>
</Tests>

This is a part of parser, which is very standard since I found it in most of tutorials:

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { 
    if(!currentElementValue)
        currentElementValue = [[NSMutableString alloc] initWithString:string];
    else
        currentElementValue = 
            (NSMutableString *) [string stringByTrimmingCharactersInSet:
                [NSCharacterSet whitespaceAndNewlineCharacterSet]];
}

And then I use this line to parse each currentElementValue into each variable of testObj

[testObj setValue:currentElementValue forKey:elementName];

The code successfully parse XML into testObj. However, the problem is in case 4, “20” is disappeared. i.e. once a element start with numeric and then follow with Chinese characters, numeric is then disappeared.

Besides, if I use:

        [currentElementValue appendString:string];

instead of:

        currentElementValue = 
            (NSMutableString *) [string stringByTrimmingCharactersInSet:
                [NSCharacterSet whitespaceAndNewlineCharacterSet]];

The elements can show all the characters but starts with many white spaces.

I would like to figure out why numeric is disappeared and look for solutions to show all characters without white spaces leading.

Thanks in advance for any help you are kind enough to provide!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:45:10+00:00Added an answer on June 18, 2026 at 6:45 am

    See the documentation of the parser:foundCharacters: delegate method:

    The parser object may send the delegate several
    parser:foundCharacters: messages to report the characters of an
    element. Because string may be only part of the total character
    content for the current element, you should append it to the current
    accumulation of characters until the element changes.

    So you have to use appendString in foundCharacters. The additional white space could be caused by the fact that you did not reset the current string in didStartElement and didEndElement:

    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
    {
         currentElementValue = nil;
    }
    
    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
    {
         if (currentElementValue) {
             NSLog(@"%@ = %@", elementName, currentElementValue);
             currentElementValue = nil;
         }
    }
    

    If necessary, you can remove unwanted white space in didEndElement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my (simplified for this case scenario) XML: <?xml version=1.0 encoding=UTF-8?> <?xml-stylesheet href=test_1.xsl
This is my xhtml code : <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC -//W3C//DTD
I have an getting an xml response on this format <?xml version=\1.0\ encoding=\utf-8\?>\r\n <PlatformResponse
I have this XML at http://localhost/file.xml : <?xml version=1.0 encoding=utf-8?> <val:Root xmlns:val=http://www.hw-group.com/XMLSchema/ste/values.xsd> <Agent> <Version>2.0.3</Version>
Given this XML: <?xml version=1.0 encoding=utf-8?> <content dataType=XML> <item type=Promotion name=Sample Promotion expires=04/01/2009> <![CDATA[
Having this XML view: <?xml version=1.0 encoding=utf-8?> <LinearLayout android:id=@+id/myScrollLayout android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical xmlns:android=http://schemas.android.com/apk/res/android> <ScrollView
I have this App.mxml: <?xml version=1.0 encoding=utf-8?> <s:Application xmlns:fx=http://ns.adobe.com/mxml/2009 xmlns:s=library://ns.adobe.com/flex/spark xmlns:mx=library://ns.adobe.com/flex/mx> <s:Button id=bt label=click
I have the following XML. <?xml version=1.0 encoding=UTF-8?> <testsuites tests=10 failures=0 disabled=0 errors=0 time=0.001
I have this simple code in facelets numbers.xhtml: <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html
I have this schema: <?xml version=1.0 encoding=UTF-8?> <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema> <xs:simpleType name=errorType> <xs:restriction base=xs:decimal> <xs:totalDigits

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.