Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Odd behaviour in processing certain nodes. #36

Open
jvanlint opened this issue Apr 27, 2015 · 1 comment
Open

Odd behaviour in processing certain nodes. #36

jvanlint opened this issue Apr 27, 2015 · 1 comment

Comments

@jvanlint
Copy link

Hi Nick,

I have the following XML

<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<startXML>
    <Contact/>
    <Dashboards>
        <Name>Dagsomsætning ugedag</Name>
        <KPI>
            <KPIName>Total salg (tDKK)</KPIName>
            <CurrentValue>8281</CurrentValue>
            <TargetValue>592</TargetValue>
            <MaxTolerance>0</MaxTolerance>
            <MinTolerance>0</MinTolerance>
            <LowIsBetter>n</LowIsBetter>
            <LastUpdate>2015-04-18 19:20:23</LastUpdate>
            <Comment/>
            <URL/>
            <DataPoints>6846</DataPoints>
            <DataPoints>6255</DataPoints>
            <DataPoints>6268</DataPoints>
            <DataPoints>6662</DataPoints>
            <ShowElipses>y</ShowElipses>
        </KPI>
        <KPI>
            <KPIName>Total salg2 (tDKK)</KPIName>
            <CurrentValue>8281</CurrentValue>
            <TargetValue>592</TargetValue>
            <MaxTolerance>0</MaxTolerance>
            <MinTolerance>0</MinTolerance>
            <LowIsBetter>n</LowIsBetter>
            <LastUpdate>2015-03-18 09:20:23</LastUpdate>
            <Comment/>
            <URL/>
            <DataPoints>6846</DataPoints>
            <DataPoints>6255</DataPoints>
            <DataPoints>6268</DataPoints>
            <DataPoints>6662</DataPoints>
            <ShowElipses>y</ShowElipses>
        </KPI>
    </Dashboards>
    <Dashboards>
        <Name>Test Board</Name>
        <KPI>
            <KPIName>Test sales (tDKK)</KPIName>
            <CurrentValue>8281</CurrentValue>
            <TargetValue>592</TargetValue>
            <MaxTolerance>0</MaxTolerance>
            <MinTolerance>0</MinTolerance>
            <LowIsBetter>n</LowIsBetter>
            <LastUpdate>2015-03-18 09:20:23</LastUpdate>
            <Comment/>
            <URL/>
            <DataPoints>6846</DataPoints>
            <DataPoints>6255</DataPoints>
            <DataPoints>6268</DataPoints>
            <DataPoints>6662</DataPoints>
            <ShowElipses>y</ShowElipses>
        </KPI>
    </Dashboards>
</startXML>

I use the [NSDictionary valueForKeyPath] method. The first Dashboard seems to process ok with KPI being a dictionary of 9 key/pair values.

The last KPI does not however and just appears to be an array of 9 key/pair values.

Here is an image illustrating what I mean.

dfsxmlparser_m

Any ideas? Is it a bug or something I am not understanding? Why is it treating the 2nd dashboard KPI differently just because it is alone?

@stkhapugin
Copy link

@jvanlint Hi! It seems like in the first Dashboard tag you have three elements: 1 Name and 2 KPI's; while in the second you have 1 KPI and 1 Name.
The second Dashboard parses to a @{@Name:@"Test Board", @"KPI":@{...}} dictionary, which sounds fairly reasonable
The first Dashboard, however, has two KPI objects, so they are parsed into an array of dictionaries that you can reference by KPI key. That makes perfect sense as well, since you can't have two distinct objects stored by the same key.

If you want to use consistent keypaths, you should try setting alwaysUseArrays to YES so that the second dashboard dictionary will have an array of a single KPI instead of a dictionary under @"KPI" key.

Hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants