0

I want to deserialize a sequence of a group of tags with SWXMLHash.

This is an example XML:

<?xml version="1.0"?>
<Places>
   <Place> 
      <name>First Place</name>
      <lon>6.775907</lon>
      <lat>51.429786</lat>
      <lon>6.775907</lon>
      <lon>6.775907</lon>
      <lat>51.429786</lat>
    </Place>
    <Place> 
       <name>Second Place</name> 
       <lon>10.885568</lon>
    </Place> 
    <Place> 
       <name>Third Place</name> 
       <lon>6.775907</lon> 
       <lat>51.429786</lat> 
       </Place>
    <Place>
       <name>Fourth Place</name> 
       <lon>10.885568</lon> 
       <lon>11.885568</lon> 
    </Place> 
</Places>

I tried following (sample) code:

struct Location: XMLIndexerDeserializable {
    let lon : Double
    let lat : Double?
    
    static func deserialize(_ node: XMLIndexer) throws -> Location {
        return try Location(
            lat: node["lat"].value(),
            lon: node["lon"].value()
        )
    }
}

struct Place: XMLIndexerDeserializable {
    let name : String
    let locations : [Location]?
    
    static func deserialize(_ node: XMLIndexer) throws -> Place {
        return try Place(
            name: node["name"].value(),
            locations: node.value()
        )
    }
}

Got an error message that node . is not valid

koen
  • 5,383
  • 7
  • 50
  • 89
PeeWee
  • 11
  • That is the `XMLDeserializationError.nodeIsInvalid` error that is fired when the element either can't be found or can't be deserialized. Without seeing either the XML being passed in or other code, it is hard to say where the error is, though. Can you provide any additional details? – David Mohundro Nov 09 '19 at 02:58
  • As an example I use this: First Place 6.775907 51.429786 6.775907 6.775907 51.429786 Second Place 10.885568 Third Place 6.775907 51.429786 Fourth Place 10.885568 11.885568 – PeeWee Nov 11 '19 at 09:10
  • Every Place has a mandatory child name, after that you have a sequence 0..infinity of mandataory lon and optional tag lat. How is it possible to desrialize this sequence? – PeeWee Nov 11 '19 at 09:12

0 Answers0