2

I am building a application in Vapor. My website works fine on localhost but on the Heroku doesn't run correctly. I have got a list with elements from xml. Xml is parsing by SWXMLHash. Heroku printing only static header. I cant see any informations about error in server log. Everything need to works fine but not working.

guard let xmlString = response?.body.bytes?.string else {
    throw Abort.custom(status: .badRequest, message: "Could not retrieve xml string")
}

let xml = SWXMLHash.parse(xmlString)
var cars:[Car] = []
for item in xml["findItemsByCategoryResponse"]["searchResult"]["item"].all {
    cars.append(Car(item:item))
    print("1 "+(item["title"].element?.text ?? ""))

}

var table:[Node]=[]
for car in cars {
    table.append(try ["title": car.title,"url": car.auctionUrl,"price":car.price,"imgUrl":car.galeryUrl].makeNode())
}
var nodeTables = try table.makeNode()
return try drop.view.make("index", Node(node: ["cars": nodeTables]))
Piotr
  • 175
  • 1
  • 2
  • 11
  • Usually no error indicates that the indexing logic is incorrect. Are you getting any elements back? For example, does `xml["findItemsByCategoryResponse"].all.count` return anything or is it 0? – David Mohundro Jan 18 '17 at 02:42
  • i can see 0. array is empty – Piotr Jan 22 '17 at 18:01
  • If it is 0, then that means that SWXMLHash isn't finding any matches. Can you post the contents of `xmlString`? Or perhaps the beginning of it? – David Mohundro Jan 22 '17 at 23:08
  • I'm having the same issue with a Vapor server on Heroku using SWXMLHash. Parsing an RSS feed locally, in debug, works like a charm and finding all child nodes is not a problem. However, after deploying to Heroku and passing in the RSS as a string to SWXMLHash returns nothing. As if it couldn't parse it. I made sure the Swift build pack was used, to note. – inreflection7 Jan 31 '17 at 19:36
  • @DavidMohundro I can reproduce the error on my Ubuntu machine as well as on Heroku with this string: `qqq`. I'm trying to do `let x = try! swxml.byKey("a")` but it throws an error: `fatal error: 'try!' expression unexpectedly raised an error: XML Element Error: Incorrect key ["a"]:`. The same code works fine on Mac. – egor.zhdan Feb 23 '17 at 10:54
  • FYI, the issue here is that Linux isn't fully supported by SWXMLHash yet because of https://bugs.swift.org/browse/SR-2301. SWXMLHash uses XMLParser from Foundation and it isn't fully implemented on Linux so it won't work there. – David Mohundro Feb 23 '17 at 19:42
  • Thanks for explanation! Will be waiting for XMLParser support in Linux. – egor.zhdan Feb 24 '17 at 14:07

1 Answers1

0

I was unable to get SWXMLHash working properly on Heroku so I opted to use XML from Zewo instead. I admit that Zewo's XML lib is not as nice to use, nor are the docs as good, as compared to SWXMLHash, but it did not take too much work to make the switch for me and works just fine on Heroku.

inreflection7
  • 1,275
  • 1
  • 11
  • 15
  • The difference between Zewo and SWXMLHash is that SWXMLHash relies on XMLParser from Foundation and it doesn't fully support Linux yet (see https://bugs.swift.org/browse/SR-2301). Zewo uses a more lower level library called libxml2 which works on Linux. – David Mohundro Feb 23 '17 at 19:44