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 6554525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:42:38+00:00 2026-05-25T12:42:38+00:00

Im trying to parse the following XML file(generated on iphone with KISSxml) with KissXML

  • 0

Im trying to parse the following XML file(generated on iphone with KISSxml) with KissXML :

<?xml version="1.0" encoding="UTF-8"?>
<SnowProfile xmlns="http://caaml.org/Schemas/V5.0/Profiles/SnowProfileIACS" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://caaml.org/Schemas/V5.0/Profiles/SnowProfileIACS http://caaml.org/Schemas/V5.0/Profiles/SnowprofileIACS/CAAMLv5_SnowProfileIACS.xsd" gml:id="2011-09-04-Home">
  <metaDataProperty>
    <MetaData>
      <dateTimeReport>2011-09-04T18:45:10-0700</dateTimeReport>
      <srcRef>
        <Operation>
          <name>My op</name>
          <contactPerson>
            <Person>
              <name>Jesse</name>
            </Person>
          </contactPerson>
        </Operation>
      </srcRef>
    </MetaData>
  </metaDataProperty>
  <validTime>
    <TimeInstant>
      <timePosition>2011-09-04T18:45:10-0700</timePosition>
    </TimeInstant>
  </validTime>
  <snowProfileResultsOf>
    <SnowProfileMeasurements dir="top down">
      <comment>Testing</comment>
      <profileDepth uom="cm">58</profileDepth>
      <skyCond>BKN</skyCond>
      <precipTI>None</precipTI>
      <airTempPres uom="degC">2</airTempPres>
      <windSpd uom="ms-1">5</windSpd>
      <windDir>
        <AspectPosition>
          <position>E</position>
        </AspectPosition>
      </windDir>
      <hS>
        <Components>
          <snowHeight uom="cm">3</snowHeight>
        </Components>
      </hS>
      <penetrationSki uom="cm">14</penetrationSki>
      <penetrationFoot uom="cm">8</penetrationFoot>
      <penetrationRam uom="cm">22</penetrationRam>
      <stratProfile>
        <Layer>
          <depthTop uom="cm">0</depthTop>
          <thickness uom="cm">27</thickness>
          <grainFormPrimary>PPsd</grainFormPrimary>
          <grainSize uom="mm">14</grainSize>
          <hardness uom="">4F</hardness>
          <lwc uom="">W</lwc>
          <density uom="kg/m3">310</density>
          <validFormationTime>
            <timeInstant>
              <timePosition>2011-09-05</timePosition>
            </timeInstant>
          </validFormationTime>
        </Layer>
        <Layer>
          <depthTop uom="cm">27</depthTop>
          <thickness uom="cm">31</thickness>
          <grainFormPrimary>PPnd</grainFormPrimary>
          <grainFormSecondary>PPpl</grainFormSecondary>
          <grainSize uom="mm">11</grainSize>
          <hardness uom="">1F</hardness>
          <lwc uom="">S</lwc>
          <density uom="kg/m3">263</density>
          <validFormationTime>
            <timeInstant>
              <timePosition>2011-07-05</timePosition>
            </timeInstant>
          </validFormationTime>
        </Layer>
      </stratProfile>
      <tempProfile uomDepth="cm" uomTemp="C">
        <Obs>
          <depth>2</depth>
          <snowTemp>0</snowTemp>
        </Obs>
        <Obs>
          <depth>18</depth>
          <snowTemp>-4</snowTemp>
        </Obs>
        <Obs>
          <depth>52</depth>
          <snowTemp>-1</snowTemp>
        </Obs>
      </tempProfile>
      <stbTests>
        <RBlockTest>
          <comment>Test</comment>
          <failedOn>
            <Layer uom="cm">
              <depthTop>25</depthTop>
            </Layer>
            <Results>
              <testScore>3</testScore>
              <fractureCharacter>Q3</fractureCharacter>
            </Results>
          </failedOn>
        </RBlockTest>
      </stbTests>
    </SnowProfileMeasurements>
  </snowProfileResultsOf>
  <locRef>
    <ObsPoint>
      <name>Home</name>
      <validElevation>
        <ElevationPosition uom="m">
          <position>110</position>
        </ElevationPosition>
      </validElevation>
      <validAspect>
        <AspectPosition>
          <position>SW</position>
        </AspectPosition>
      </validAspect>
      <validSlopeAngle>
        <SlopeAnglePosition uom="deg">
          <position>2</position>
        </SlopeAnglePosition>
      </validSlopeAngle>
      <pointLocation>
        <gml:Point srsDimension="2">
          <gml:pos></gml:pos>
        </gml:Point>
      </pointLocation>
    </ObsPoint>
  </locRef>
</SnowProfile>

Using the following code to create a core data object from it:

-(BOOL)importFile:(NSString *)fileName error:(NSError **)error{
    NSData *data = [[NSData alloc] initWithContentsOfFile:fileName];
    if(data == nil)
        return NO;
    DDXMLDocument *doc = [[DDXMLDocument alloc] initWithData:data options:0 error:error];
    //if(error != nil)
    if(doc == nil)
        return NO;

    snowPit *pit = [snowPit pitForCAAMLProfile:doc];
    if(pit != nil)
        return YES;
    else
        return NO;
}

+(snowPit *)pitForCAAMLProfile:(DDXMLDocument *)xmlDoc{
    NSLog(@"%@", [xmlDoc XMLStringWithOptions:DDXMLNodePrettyPrint] );

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
    NSError *err;

    snowPit *newPit = [[pitManager sharedManager] newPitWithoutDefaults];
    NSArray *fields = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"CAAMLImportFields" ofType:@"plist"]];
    for(NSDictionary *importField in fields){
        NSString *field = [importField valueForKey:@"field"];
        NSString *xpath = [importField valueForKey:@"xpath"];
        NSString *attribute = [importField valueForKey:@"attribute"];
        NSArray *nodes;
        if(xpath != nil && [xpath length] > 0){
            nodes = [xmlDoc nodesForXPath:xpath error:nil];
            NSLog(@"Field:%@, xpath:%@, attribute:%@ nodes:%i", field, xpath, attribute, [nodes count]);
            if(nodes != nil && [nodes count] > 0){
                NSString *value;
                if(attribute != nil && [attribute length] > 0){
                    DDXMLNode *attNode = [[nodes objectAtIndex:0] attributeForName:attribute];
                    if(attNode != nil)
                        value = [attNode stringValue];
                }else
                    value = [[nodes objectAtIndex:0] stringValue];
                if(value != nil && [value length] > 0)
                    [newPit setValue:value forKey:field];
            }
        }
    }
    [dateFormatter release];
    return newPit;
}

But so far every XPath query I try returns an array of 0 length.

To get the value for name i have tried //Person/name Person/name //name name And they all return a 0 length array. Even a query for /SnowProfile returns a 0 length array which leads me to think that something is going wrong with the xml parsing. I have validated the XML file and it is fine, and from the NSlog output I can tell that the file is being loaded.

  • 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-05-25T12:42:39+00:00Added an answer on May 25, 2026 at 12:42 pm

    There is a namespace defined xmlns:gml="http://www.opengis.net/gml"

    From my recollection of xpath, you need to specify that when you do an xpath query. Try /gml:SnowProfile to see if that returns something other than a 0 length array. You will then know if this will solve your problem.

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

Sidebar

Related Questions

I am trying to parse the following XML with javascript: <?xml version='1.0' encoding='UTF-8'?> <ResultSet>
Something's screwy here. I'm trying to parse this XSL file: <?xml version=1.0 encoding=utf-8?> <xsl:stylesheet
I have the following xml file: <?xml version=1.0 encoding=UTF-8?> <c1> <c2 id=0001 n=CM urlget=/at/CsM
I have an XML file of the following structure: <?xml version=1.0 encoding=utf-8?> <root> <ArrayOfLocationDTO
I am trying to parse the following XML file in Java and to store
Is the following format correct for XML? I am trying to parse the file
I'm new to xml parsing, I am trying to parse the following xml file
I am trying to parse an xml log file in PHP. It has following
I have the following xml snippet: <?xml version=1.0 encoding=UTF-8 ?> <!DOCTYPE sqlMap PUBLIC -//ibatis.apache.org//DTD
I have a simple xml file that looks like this: <?xml version=1.0 encoding=UTF-8 standalone=yes

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.