We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Mapping an XML element that have other elements of basic type and attributes:
<Person gender="male"> <FirstName>First</FirstName> <LastName>Last</LastName> </Person>
is easy:
class Person: XMLMappable { var nodeName: String! var gender: String? var firstName: String? var lastName: String? required init(map: XMLMap) { } func mapping(map: XMLMap) { gender <- map.attributes["gender"] firstName <- map["FirstName"] lastName <- map["LastName"] } }
But if I try to map an XML element of basic type (like Person below) that have attributes:
Person
<root> <Person gender="male">First Last</Person> </root>
Using this:
class Root: XMLMappable { var nodeName: String! var person: String? required init(map: XMLMap) { } func mapping(map: XMLMap) { person <- map["Person"] } }
I am getting nil in person property and using this:
nil
person
class Root: XMLMappable { var nodeName: String! var person: Person? required init(map: XMLMap) { } func mapping(map: XMLMap) { person <- map["Person"] } } class Person: XMLMappable { var nodeName: String! var gender: String? var name: String? required init(map: XMLMap) { } func mapping(map: XMLMap) { gender <- map.attributes["gender"] //name <- get somehow innertext } }
I am getting correctly the gender attribute but I don't know how to get Person's name.
gender
The text was updated successfully, but these errors were encountered:
With the next release (probably 1.4.2) you can map directly the text of the current XML node using the innerText property of XMLMap like:
innerText
XMLMap
class Person: XMLMappable { var nodeName: String! var gender: String? var name: String? required init(map: XMLMap) { } func mapping(map: XMLMap) { gender <- map.attributes["gender"] name <- map.innerText } }
Sorry, something went wrong.
5f7c23c
gcharita
No branches or pull requests
Mapping an XML element that have other elements of basic type and attributes:
is easy:
But if I try to map an XML element of basic type (like
Person
below) that have attributes:Using this:
I am getting
nil
inperson
property and using this:I am getting correctly the
gender
attribute but I don't know how to getPerson
's name.The text was updated successfully, but these errors were encountered: