Giter Site home page Giter Site logo

CData Not parsing about xmlreader HOT 2 OPEN

amarcadet avatar amarcadet commented on September 28, 2024
CData Not parsing

from xmlreader.

Comments (2)

amarcadet avatar amarcadet commented on September 28, 2024

Hi, sorry for the delay. I assume that you have found a solution by now.

Would you mind to share it or open a PR with it?

I am trying to clean my issues and give that repository more attention than during the past.

from xmlreader.

Prarik avatar Prarik commented on September 28, 2024

Actually i have implemented the above method nothing new.

But sure i want to share following method which i used to clean-up the NSDictionary and generate the better output of the XML.

  1. First parse the XML using XMLReader.
  2. Than pass that dictionary into following method and compare before and after clean-up dictionary.
  3. I have changed NSString *const kXMLReaderTextNodeKey = @"temp"; in XMLReader.
#define kXMLDefaultKey @"text"
/**
 *  This method is used to clean up dictionary which we get after XML parsing
 *
 *  @param XMLDictionary Dictionary on which we want to perform cleanup
 *
 *  @return Cleaned dictionary
 */
+ (NSMutableDictionary *)cleanUpXMLDictionary:(NSMutableDictionary *)XMLDictionary
{
    for (NSString *key in [XMLDictionary allKeys]) {
        // get the current object for this key
        id object = [XMLDictionary objectForKey:key];

        if ([object isKindOfClass:[NSDictionary class]]) {
            if ([[object allKeys] count] == 1 &&
                [[[object allKeys] objectAtIndex:0] isEqualToString:kXMLDefaultKey] &&
                ![[object objectForKey:kXMLDefaultKey] isKindOfClass:[NSDictionary class]]) {
                // this means the object has the key "text" and has no node
                // or array (for multiple values) attached to it.
                [XMLDictionary setObject:[object objectForKey:kXMLDefaultKey] forKey:key];
            }
            else {
                // go deeper
                [self cleanUpXMLDictionary:object];
            }
        }
        else if ([object isKindOfClass:[NSArray class]]) {
            // this is an array of dictionaries, iterate
            for (id inArrayObject in (NSArray *)object) {
                if ([inArrayObject isKindOfClass:[NSDictionary class]]) {
                    // if this is a dictionary, go deeper
                    [self cleanUpXMLDictionary:inArrayObject];
                }
            }
        }
    }

    return XMLDictionary;
}

from xmlreader.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.