chenyunguimilook / swiftyxml Goto Github PK
View Code? Open in Web Editor NEWThe most swifty way to deal with XML data in swift 5.
License: MIT License
The most swifty way to deal with XML data in swift 5.
License: MIT License
<catalog>
<product description="Cardigan Sweater" product_image="cardigan.jpg" >
<catalog_item gender="Men's" >
<item_number>QWZ5671</item_number>
<price>39.95</price>
<size description="Medium" >
<color_swatch image="red_cardigan.jpg" >Red</color_swatch>
<color_swatch image="burgundy_cardigan.jpg" >Burgundy</color_swatch>
</size>
<size description="Large" >
<color_swatch image="red_cardigan.jpg" >Red</color_swatch>
<color_swatch image="burgundy_cardigan.jpg" >Burgundy</color_swatch>
</size>
</catalog_item>
<catalog_item gender="Women's" >
<item_number>RRX9856</item_number>
<price>42.50</price>
<size description="Small" >
<color_swatch image="red_cardigan.jpg" >Red</color_swatch>
<color_swatch image="navy_cardigan.jpg" >Navy</color_swatch>
<color_swatch image="burgundy_cardigan.jpg" >Burgundy</color_swatch>
</size>
</catalog_item>
</product>
</catalog>
How to make escaping sequence String from XML? For write-in file and send on the server. Thanks.
My Xml has a lot of values separated by hyphen like "display-name
" or "item-id
", but I can't figure ii out on how to access to its values.
If I use the readme instructions like this:
let name = xml.channel.0.display-name.string
Binary operator '-' cannot be applied to operands of type 'XMLSubscriptResult' and 'String'
Is there any way to achieve this ?
import SwiftyXML Module compiled with Swift 3.1 cannot be imported in Swift 4.0
let newXML = LocalDataModelXML.newTasksXML!
newXML.addChild(XML(string: tasks))
If construct XML from existing XML new tag added new tag and not parse new tag.
After parse final xml view one first tag
<Doc StatusDoc="new" >
<clientsTasks>
<clientTask description="Dsdsd" persone="Гребенкина Анастасия" date="1562290361.0" id_client="000006383" name="Dodd’s" />
</clientsTasks>
<clientsTasks>
<clientTask description="Dsdsd" date="1562463999.0" id_client="000006383" persone="Гребенкина Анастасия" name="dsdsdds" />
</clientsTasks>
<clientsTasks>
<clientTask name="dsdsdds" description="Dsdsd" date="1562463999.0" id_client="000006383" persone="Гребенкина Анастасия" />
</clientsTasks>
<clientsTasks>
<clientTask date="1562463999.0" persone="Гребенкина Анастасия" description="Dsdsd" id_client="000006383" name="dsdsdds" />
</clientsTasks>
<clientsTasks>
<clientTask id_client="000006383" name="dsdsdds" date="1562463999.0" persone="Гребенкина Анастасия" description="Dsdsd" />
</clientsTasks>
<clientsTasks>
<clientTask persone="Гребенкина Анастасия" date="1562207178.0" description="dsdsd" id_client="000006383" name="dsdsd" />
</clientsTasks>
<clientsTasks>
<clientTask date="1562121435.0" description="Hello" persone="Казакова Анастасия" name="test update view" id_client="000006383" />
</clientsTasks>
</Doc>
CocoaPods
and Carthage
are awesome tools and make our life really easier, but there are some devs who still don't know how to use them.
It would be cool to add the Manual installation guide in your README.md
. You can take a look at my iOS Readme Template to see how you can do it.
Is there any method to catch invalid XML and throw an error without crashing the app?
In the attached xml response (Google geocode response.pdf, this is the response from url https://maps.googleapis.com/maps/api/geocode/xml?&latlng=63,10), the value of xml["result"][0]["address_component"][3]["short_name"].stringValue is "ør-Trøndelag" (xml is the value of XML(data: data) from the response (using Alamofire)). The correct response should be "Sør-Trøndelag". Thus, the first S is missing. I have also seen other examples where multiple (all) characters before the first non-ascii character is removed in the stringValue.
For make true XML need in the loop get all value and fix then.
Example:
let newXMLHead: XML = XML(name: "clients")
let usersXML: [XML] = memoryXML!["#clients"]["client"].xmlList!
for value in usersXML {
let newXML: XML = XML(name: "clients")
for (key, subValue) in value.attributes {
newXML.addAttribute(name: key, value: subValue.percentEscapeString())
}
newXMLHead.addChild(newXML)
}
Where
extension String {
func percentEscapeString() -> String {
return self
.replacingOccurrences(of: "&", with: "&")
.replacingOccurrences(of: """, with: """)
.replacingOccurrences(of: "'", with: "'")
.replacingOccurrences(of: ">", with: ">")
.replacingOccurrences(of: "<", with: "<")
}
}
Originally posted by @kiri11ko in #8 (comment)
The public properties of the XML class (name, attributes, value and children) can mask child XML elements with the same element name when attempting to use DynamicMemberLookup to traverse the XML chain.
A real-world occurrence of this issue is that full traversal of the xml tree of the GPX file format (https://en.wikipedia.org/wiki/GPS_Exchange_Format) using DynamicMemberLookup is impossible because of child elements named as "name" in the wptType, rteType, trkType and personType elements.
I have created a pull request for a suggested fix that renames the public properties of the XML class by adding xml... as a prefix to the property name.
Hey,
First of all, I must say this is a great control.
But I would like to ask is there anyway to access the value by using attributes? Like in your example,
let color0 = xml["product"]["catalog_item"]["size"]["color_swatch"][1].string //"Burgundy"
Can I access the value "Burgundy" without using the number (1 in this case), but with the file name "burgundy_cardigan.jpg"? Thanks!
I am trying to add CDATA when constructing an XML but cannot seem to figure it out. Any tips?
In your example xml, how would you delete a complete tag: for example everything between <catalog_item> and </catalog_item> including the starting and ending tags? I want to replace a complete item with an updated version.
Many thanks
Robert
I'd be cool to also add Cocoapods support. I done this implementation myself last week for my library. Just follow this post and this checklist.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.