Code Monkey home page Code Monkey logo

swxmlhash's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swxmlhash's Issues

Issue when return string

Hi,
when I try to print some text value , it return optional(" ----text ")
for example if I have this xml:
<root>
...
<catalog>
<book>Bob</book>
<book>John</book>
<book>Mark</book>
</catalog>
...
</root>

when I try to print xml["root"]["catalog"]["book"][1]["author"].element?.text

the output is optional( " John ") instade of "John".

Any idea?

Carthage installation issue

Hi,

When I tried installing SWXMLHash using Carthage, I got the following error

The following build commands failed:
Check dependencies
(1 failure)
Code Sign error: No code signing identities found: No valid signing identities (i.e. certificate and private key pair) matching the team ID “(null)” were found.
CodeSign error: code signing is required for product type 'Framework' in SDK 'iOS 8.4'

Please help.

Swift 1.2 merge

When is the Xcode 6.3 branch going to be merged into master and pushed to Cocoapods?

I'm waiting on this right now! :) Thanks.

Carthage using builds unnecessary dependencies

Nimble and Quick dependencies are builded too, because they have shared scheme in project. But I want to use SWXMLHash and Nimble or Quick are worthless for me. And it takes some time when more frameworks is builded.

SWXMLHash.parse missing some data

When i put message
responseData = <div>
<div>
<div class="h">Header 1</div>
<div class="b">Body</div>
<div class="f">Footer</div>
</div>
<div>
<div class="h">Header 2</div>
<div class="b">Body</div>
<div class="f">Footer</div>
</div>
<div>
<div class="h">Header 3</div>
<div class="b">Body</div>
<div class="f">Footer</div>
</div>
<div>
<div class="h">Header 4</div>
<div class="b">Body</div>
<div class="f">Footer</div>
</div>
<div>
<div class="h">Header 5</div>
<div class="b">Body</div>
<div class="f">Footer</div>
</div>
</div>
"
let xml = SWXMLHash.parse(responseData )
and println(xml)
"
<div>
<div>
<div class="h">Header 1</div>
<div class="b">Body</div>
<div class="f">Footer</div>
</div>
<div>
<div class="h">Header 2</div>
<div class="b">Body</div>
<div class="f">Footer</div>
</div>
"

It just has only 2 childs.
Please help

Type conversion fails with lazily loaded XML

When using XML parsed with the SWXMLHash.lazy() method, the type conversion to an array fails with a XMLDeserializationError.NodeIsInvalid

The problem is fixed when changing to SWXMLHash.parse()

Need help parsing an array node

Hi,

I have an xml which looks like the below:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <GetAssociatedProjectsIDsResponse>
            <GetAssociatedProjectsIDsResult xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
                <a:int>2947</a:int>
                <a:int>3847</a:int>
                <a:int>2675</a:int>
                <a:int>9875</a:int>
            </GetAssociatedProjectsIDsResult>
        </GetAssociatedProjectsIDsResponse>
    </s:Body>
</s:Envelope>

Is there a way to iterate within all 'int' elements inside 'GetAssociatedProjectsIDsResult'?

Compile error - CLI Project

Initial Cococapod install worked and I was able to play around in playground.

I then went to implement the code outside of the playground by adding "import SWXMLHash". I know get the following compile error

"<unknown>:0: error: could not build Objective-C module 'SWXMLHash'" 

which isn't very helpful

My playground also stopped working with the following error

"Playground execution failed: could not build Objective-C module 'SWXMLHash'A fatal parse error has occurred.  LLDB may become unstable; please restart your debug session as soon as possible."

I suspect it is an Xcode build / config problem or pod build problem since it initial worked in the playground.

I tried replicating the initial setup that worked with the playground, but haven't been able to.

I am lost at how to track the issue down? Any tips, tricks or suggestions?

EXC_BAD_ACCESS

let parser = NSXMLParser(data: data)
parser.shouldProcessNamespaces = options.shouldProcessNamespaces
parser.delegate = self
parser.parse() ----> Line 227 - EXC_BAD_ACCESS (code=2, address=0x10f388000)

Occurs when running in iOS simulator

Parsing question

First off, many thanks for this library and great work

I managed to get the rss xml parsed and it looks like this

<rss version="2.0">
     <channel>
        <title>
       </title>
        <title>
       </title>
         .......
     </channel>
</rss>

So I'm trying to extract the title as such but its not returning anything.

        for elem in xml["rss version=\"2.0\""]["channel"] {

            print(elem["title"].element!.text!)
        }

Deserializing a single element into an array

Hi there, I'm wondering if its possible to deserialize a single XML element into an array.

For example with the given xml
<distances>1,2,3,4,5,6,7</distances>

Is it possible to deserialize into [Int] ?

Thanks!

Async NSXML can’t work in sync mode, please add completion handlers

Sometimes “parse” method returns an empty object (every 4-5th execution)

Code:
let xml = SWXMLHash.parse(data)

Log:
(lldb) po xml
Element { Element = 0x00007f93f2e18960 { name = "SWXMLHash_Root_Element" text = nil attributes = {} children = 0 values {} count = 0 index = 0 } }

(lldb) po data
<OS_dispatch_data: data[0x7f93f2e29830] = { composite, size = 2031, num_records = 2 record[0] = { from = 0, length = 1297, data_object = 0x7f93f2ccdff0 }, record[1] = { from = 0, length = 734, data_object = 0x7f93f2e157c0 }, }>

Printing 'nil' for every value I try to retrieve

Hello,

I'm trying to get SWXMLHash working with my project. I have the URL of an XML file. When I try to retrieve the 'text' of certain elements, as well as attributes, I keep getting 'nil'. I must be doing something wrong, but I don't know what.

I've installed SWXMLHash via CocoaPods.

A sample of what the XML file looks like is,

<coord2 count="9">
  <markers>
    <marker>
      <lat>36.97734</lat>
      <lng>-122.05444</lng>
      <timestamp>1445016544</timestamp>
      <route>LOOP</route>
      <id>7855</id>
      <predictions>
      ,8,9,,10,11,,,,14,,,15,,15,,17,1,,0,,,3,,,4,,,6,,,,,,,,,,,,,,
      </predictions>
      <update_seconds>10</update_seconds>
      <index>0</index>
    </marker>
    <marker>
      <lat>36.97772667</lat>
      <lng>-122.053615</lng>
      <timestamp>1445016539</timestamp>
      <route>LOOP</route>
      <id>7860</id>
      <predictions>
      9,,,8,,,7,6,5,,4,3,,2,,1,,,0,,15,14,,13,12,,11,10,,,,,,,,,,,,,,,
      </predictions>
      <update_seconds>10</update_seconds>
      <index>0</index>
    </marker>
  </markers>
  <curr_time>1445016544</curr_time>
</coord2>

The following is what my code looks like,

import UIKit
import SWXMLHash

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        let xml = SWXMLHash.config {
            config in
            config.shouldProcessNamespaces = true
            }.parse("http://url.to.xmlfile.xml")

        print(xml["coord2"].element?.attributes["count"])
        print(xml["coord2"]["markers"]["marker"][0]["lat"].element?.text)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

I'm expecting my program to output:
9
36.97734

but I'm getting:
nil
nil

I am running Xcode v 7.0.1 (Swift 2.0 I think).

Thank you for your help!

watchOS Support?

[!] The platform of the target Watch Extension (watchOS 2.0) is not compatible with SWXMLHash (2.0.0), which does not support watchos.

and there is my podfile

use_frameworks!
inhibit_all_warnings!

target 'MyMainAppTarget' do
    platform :ios, '8.0'

    ...
end

target 'MyWatchExtensionTarget' do
    platform :watchos, '2.0'

    pod 'SWXMLHash'
end

Incomplete XML

Hello,

I have the bellow code:

let xml = SWXMLHash.parse(data!)

let servResponse = xml["response"]["sucesso"].element?.text == "true" ? true : false

if servResponse == true {

      let resData = xml["response"]

       for obj in resData["XMLGridData"] {

        ...

       }

}

The XML that I'm looping is huge and contains 200 tags of "XMLGridData"..

But when I do the SWXMLHash.parse(data!) from the Alamofire it only iterates with 10 tags of "XMLGridData".

See the Xml limited
<response> <sucesso>true</sucesso> <retorno>Consulta Realizada Com Sucesso!</retorno> <XMLGridData> <Bike_Sq>2</Bike_Sq> <Bk_Bike_ID>1</Bk_Bike_ID> <PT_agency_id>1</PT_agency_id> <PT_agency_name>Bikesampa</PT_agency_name> <Bk_PL_ID>2</Bk_PL_ID> <Bk_Total>12</Bk_Total> <Bk_Available>1</Bk_Available> <Bk_Last_UPDATE>2016-05-15T19:00:00</Bk_Last_UPDATE> <Bk_Active>1</Bk_Active> <PL_LT>-2.358731500000000e+001</PL_LT> <PL_LG>-4.664797400000000e+001</PL_LG> <PL_Desc>BikeSampa -Instituto Biologico</PL_Desc> </XMLGridData> <XMLGridData> <Bike_Sq>3</Bike_Sq> <Bk_Bike_ID>2</Bk_Bike_ID> <PT_agency_id>1</PT_agency_id> <PT_agency_name>Bikesampa</PT_agency_name> <Bk_PL_ID>3</Bk_PL_ID> <Bk_Total>14</Bk_Total> <Bk_Available>0</Bk_Available> <Bk_Last_UPDATE>2016-05-15T19:00:00</Bk_Last_UPDATE> <Bk_Active>1</Bk_Active> <PL_LT>-2.359222700000000e+001</PL_LT> <PL_LG>-4.664684400000000e+001</PL_LG> <PL_Desc>BikeSampa -Cinemateca</PL_Desc> </XMLGridData> <XMLGridData> <Bike_Sq>4</Bike_Sq> <Bk_Bike_ID>3</Bk_Bike_ID> <PT_agency_id>1</PT_agency_id> <PT_agency_name>Bikesampa</PT_agency_name> <Bk_PL_ID>4</Bk_PL_ID> <Bk_Total>12</Bk_Total> <Bk_Available>1</Bk_Available> <Bk_Last_UPDATE>2016-05-15T19:00:00</Bk_Last_UPDATE> <Bk_Active>1</Bk_Active> <PL_LT>-2.359309900000000e+001</PL_LT> <PL_LG>-4.664239800000000e+001</PL_LG> <PL_Desc>BikeSampa -Capitao Macedo</PL_Desc> </XMLGridData> <XMLGridData> <Bike_Sq>5</Bike_Sq> <Bk_Bike_ID>4</Bk_Bike_ID> <PT_agency_id>1</PT_agency_id> <PT_agency_name>Bikesampa</PT_agency_name> <Bk_PL_ID>5</Bk_PL_ID> <Bk_Total>12</Bk_Total> <Bk_Available>2</Bk_Available> <Bk_Last_UPDATE>2016-05-15T19:00:00</Bk_Last_UPDATE> <Bk_Active>1</Bk_Active> <PL_LT>-2.358947200000000e+001</PL_LT> <PL_LG>-4.663995300000000e+001</PL_LG> <PL_Desc>BikeSampa -Belas Artes</PL_Desc> </XMLGridData> ..... </response>

I have checked the data from Alamofire and it is complete.

Could you please help me with this?

tvOS target has no sources to compile :\

Hi David,

Just got around to adding the tvOS framework to my project (spent the last week writing an importer to capture data which was mostly under OS X) and noticed I was getting an error in the editor when I tried to write

let xml = SWXMLHash.parse(data!)

that there was no parse method on the object when using the framework in the tvOS branch. I'd been using it all week in iOS and OS X so that was a little confusing :| ...turns out the swift file isn't in the build list for tvOS:

screen shot 2015-11-20 at 3 43 45 pm

(just did a fresh pull, just to check, and it's the same on the master branch)

Ensure everything works in XCode 6 beta 4.

Now that XCode 6 beta 4 is out, everything needs to be reviewed.

  • The specs currently are not running because Quick hasn't had a chance to update to XCode 6 beta 4... it will need to update (which I think mainly includes adding public accessors) before it will be usable again.
  • Public accessors will need to be added to everything that will be usable outside of the library.

Parsing XML with namespaces

Currently, there is no way to set the XMLParser shouldProcessNamespaces to true. So when accessing an element, the complete tagname with namespace needs to be passed. e.g xml["f:animal"] instead of just xml["animal"]

In the example in the code, it would be nice if instead of this

xml["root"]["h:table"]["h:tr"]["h:td"][0].element!.text!

we will have this

xml["root"]["table"]["tr"]["td"][0].element!.text!

watchOS build doesn't actually include the source file

I was banging my head against this for a couple of hours, getting an error "Module SWXMLHash has no member named ‘parse" in my WatchKit extension code. It turned out that the SWXMLHash WatchOS target doesn't actually include the single SWXMLHash.swift source file in its WatchOS target, so indeed, the framework really didn't have a member named parse.

I fixed this locally by selecting the project to see build settings, selecting the WatchOS target, then Build Phases > Compile Sources, then dragged SWXMLHash.swift into the empty list of source files.

I'd submit a pull request to fix this, but given it's project settings, it's probably easier for all concerned for you (the author) to make the change directly, though I can submit a PR if you prefer.

Add support for automatic deserialization of Bool types

The automatic type conversion in #68 lacks support for Bool types. The W3C specification defines a boolean as follows:

3.2.2.1 Lexical representation

An instance of a datatype that is defined as ·boolean· can have the following legal literals {true, false, 1, 0}.

SWXMLHash should support automatic decoding of at least these four values into Swift Bool primitives.

Does it return NSArray or NSDictionary?

    var xml = NSData(contentsOfFile: NSString(format: "%@/test.xml", NSBundle.mainBundle().resourcePath!));
    let dom = SWXMLHash.parse(xml)

    let elems = dom["root"]
    for e in elems {

    }

I got the following error message:

Type 'XMLIndexer' does not conform to protocol 'SequenceType'

How can it be supported? Thanks

Getting entire HTML between opening and closing tag.

My question might be a little bit lame but I just can't figure it out. How to get everything between opening and closing html tag?
For example now I have
let b = xml["everything"]["news"][i]["content"].element?.text
which returns string:
Click this for super cool news.
and I would like it to return
Click this <a href="https://www.link.com">link</a> for super cool news.
Thank you for help.

Outputting XML and writing XML?

Beautifully written library. Congratulations!
I noticed that I can assign in new value to the text of an element, because it's a var string optional, so that works great. I hope I'm doing that the way that you intended.

let filePath = NSBundle(forClass: self.classForCoder).pathForResource("cds", ofType: "xml")
var contents = File.open(filePath!, utf8: NSUTF8StringEncoding)!
let xml = SWXMLHash.parse(contents)
println(xml["CATALOG"]["CD"][0]["TITLE"].element?.text!)
// is this how I should set the new text?
xml["CATALOG"]["CD"][0]["TITLE"].element?.text = "New Text"
//Output XML here somehow. 

I'm wondering if I can output the new XML so I can save it to document?

I understand the objects that all and children return. I was about to write something that would output the new XML with the new values. I wasn't sure if there was a easy way to get that without having to write something special that outputs XML.

For this example I am using this XML as an example:
http://www.w3schools.com/xml/cd_catalog.xml

Add automatic deserialization of attributes.

Recent pull request #68 from @ncreated introduced automatic type conversion for Elements and Indexers, but working with attributes is still painful. I am working with some (imo) poorly designed XML, which has a number of elements like this:

<stats minplayers="2" maxplayers="2" minplaytime="40" maxplaytime="60" playingtime="60" numowned="253" rating="8.5">

It would be nice to be able to automatically convert these attributes into Int, Float, Double, Bool, and String types (as well as Int?, Float?, etc...) with a syntax similar to node["test"].value().

As it stands now, when processing attributes within a deserializer, I need to do crazy optional gymnastics, like this:

var minPlayers: Int
if let minPlayersString = node["stats"].attribute("minplayers") {
   if let minPlayersInt = Int(minPlayersString) {
      minPlayers = minPlayersInt
   }
}

I would love to be able to replace this with something like this:
var minPlayers: Int = node["stats"].attribute("minplayers")

Swift's 'guard' syntax makes this slightly less laborious if the values are guaranteed to be there, but there is still certainly room for improvement.

Help in parsing this xml format

Could you please help me in parsing this format.
I am not able to correctly parse this kind of format: I want to get the 'text' attributes value of all prop given 'child' index value.
For ex: get all prop's 'text' value given 'child' index 1
root
child index="1" name="child name 1"
prop index="1" text="prop name1" /
prop index="2" text="prop name2" /
/child
child index="2" name="child name 2"
prop index="1" text="prop name1" /
prop index="2" text="prop name2" /
/child
/root

Possible problem when using SWXMLHash inside a framework

Please have a look at https://github.com/tkrajacic/XMLTestWithFramework
It is a minimal crashing example.

When the application is finished processing the XML file it crashes when trying to over-release some CFString. This only happens when using a NSNumberFormatter to parse a String out of the XML.
When commenting out the String parsing, everything works.

I am not sure if I am making a mistake using SWXMLHash here or if it is a bug inside SWXMLHash.

Any help would be appreciated!

Add Carthage Support

I'm currently working on a fork to add this, but if you want to add it before then that would be killer.

tvOS target?

Hi

Would it be possible to get a tvOS target? (I've forked a copy and added the new target for tvOS, and it seems to compiles fine, and even builds a framework but I couldn't get Carthage to see the tvOS scheme... I'll be happy to issue a PR for my (utterly trivial) changes but might be faster for you to just add the target).

best,
David

Allow easy enumeration of child elements.

I thought that .all would allow for easy enumeration of child elements (such as when the XML is dynamic), but it doesn't appear to work.

The API I have in mind is something like:

func enumerate(xml: XMLIndexer) {
    for elem in xml.all {
        enumerate(elem)
    }
}

enumerate(xml)

Cannot compile with Xcode 6.1.1

When I add SWXMLHash.swift to my project I get the following errors:

Errors

Am I doing something wrong? I'm using OSX 10.10 and targeting My Mac.

API Review before 1.0 release

The current release is 0.6.0. I want to ensure the API is solid before calling this 1.0 (as I'd like to use semantic versioning). I'd welcome thoughts or suggestions from anyone who makes use of this library, particularly if some method or property names aren't particularly clear.

Some general thoughts:

  • Documentation currently refers to a "current level" of indexing (i.e. xml["root"]["header"] is indexing down to "root" and "header"), but this seems vague to me. I'm like to re-think how to describe this.
    • As examples, the all and children properties behave differently depending on where the code has indexed to.
  • Both all and children might be too vague in their names.

I may consider renaming some methods and properties to help with clarity, but again, I'd welcome input, too.

XML with mixed content isn't currently supported

I discovered that XML that has mixed content (i.e. both child elements and text) isn't currently supported.

For example:

<root>
  <header>
    header mixed content
    <title>Test Title Header</title>
  </header>
</root>

The following is a failing spec (it actually returns nil at the moment):

it("should be able to handle mixed content") {
  expect(xml["root"]["header"].element?.text).to(equal("header mixed content"))
}

iOS9?

i see that it's targetting iOS8. will this work on iOS9 as well?

I'm running swift 2 and ios9, just curious if this is will work or not?

I'm unable to use the framework in the playground

The framework is working fine in my project, but I'm unable to import the framework in the playground.

I keep having this output in the console:
Playground execution failed: bart-Sample-playground.playground:4:8: error: no such module 'SWXMLHash'

import SWXMLHash
^

  • I tried to delete the content of the derived data folder.
  • I also tried to clean and build.

How can I use the framework inside a playground ?

Getting Attribute count to add values to an array in Swift with SWXMLHash

Here is the XML I'm parsing with SWXMLHash:

<response version="1.2" xsi:noNamespaceSchemaLocation="http://aviationweather.gov/adds/schema/metar1_2.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance">'
    <request_index>7394484</request_index>
    <data_source name="metars"/>
    <request type="retrieve"/>
    <errors/>
    <warnings/>
    <time_taken_ms>4</time_taken_ms>
    <data num_results="1">
        <METAR>
            <raw_text>KDEN 261153Z 07012KT 3SM -FZDZSN BKN004 OVC008 M05/M06 A3009 RMK AO2 SLP213 P0000 60000 I1000 I6000 T10501061 11039 21050 53009</raw_text>
            <station_id>KDEN</station_id>
            <observation_time>2015-11-26T11:53:00Z</observation_time>
            <latitude>39.85</latitude>
            <longitude>-104.65</longitude>
            <temp_c>-5.0</temp_c>
            <dewpoint_c>-6.1</dewpoint_c>
            <wind_dir_degrees>70</wind_dir_degrees>
            <wind_speed_kt>12</wind_speed_kt>
            <visibility_statute_mi>3.0</visibility_statute_mi>
            <altim_in_hg>30.088583</altim_in_hg>
            <sea_level_pressure_mb>1021.3</sea_level_pressure_mb>
            <quality_control_flags>
                <auto_station>TRUE</auto_station>
            </quality_control_flags>
            <wx_string>-FZDZ SN</wx_string>
            <sky_condition cloud_base_ft_agl="400" sky_cover="BKN"/>
            <sky_condition cloud_base_ft_agl="800" sky_cover="OVC"/>
            <flight_category>LIFR</flight_category>
            <three_hr_pressure_tendency_mb>0.9</three_hr_pressure_tendency_mb>
            <maxT_c>-3.9</maxT_c>
            <minT_c>-5.0</minT_c>
            <precip_in>0.005</precip_in>
            <metar_type>SPECI</metar_type>
            <elevation_m>1640.0</elevation_m>
        </METAR>
    </data>
</response> 

I want to get the count of sky_condition sky_cover sky_base_ft_agl as there is always at least one with no cloud base (CLR) or multiple FEW, BKN or OVC with cloud bases with each. I want to be able to get the number of sky conditions and then enumerate through them and add them to an array so that I can show them on a label together.

Here is the code I have to get the data to parse and then present to a label:

 func getWxData () {

        let urlStringMax = "https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&hoursBeforeNow=3&mostRecent=true&stationString=KDEN"

    if let urlMax = NSURL(string: urlStringMax) {

        if let data = try? NSData(contentsOfURL: urlMax, options: []) {

           let xml = SWXMLHash.parse(data)
           print(xml)

            metar1 = xml["response"]["data"]["METAR"]["raw_text"].element!.text!
           skycover = xml["response"]["data"]["METAR"]["sky_condition"][0].element?.attributes["sky_cover"]
         print(skycover)

            }
        }
    }

Any help would be greatly appreciated!!

Add Travis CI integration

I've started this by adding a .travis.yml file, but it isn't building yet... still working out Carthage and pulling in Quick/Nimble so that the tests can be run.

A weird parser error.

Hello, Thank you for your framework.

I have a Custom UIView Template written in XML. And there's seems to be an escaping issue and I have no idea how to fix it. My XML seems right.

Here's the XML Template:

<?xml version="1.0" encoding="UTF-8"?>
<niotemplate version="1.0">
    <section>
        <textfield id="title" tinted="true" size="15">
            <placeholder>
                <en>Title</en>
            </placeholder>
        </textfield>
        <constraint>V:|-10-[title]-10-|</constraint>
        <constraint>H:|-15-[title]-15-|</constraint>
    </section>
    <section>
        <textview id="content" parser="markdown" editable="true" size="14" auto-height="true"/>
        <constraint>H:|-15-[content]-15-|</constraint>
        <constraint>V:|-10-[content]-10-|</constraint>
    </section>
</niotemplate>

There's an error when parsing <constraint>H:|-15-[title]-15-|</constraint>. SWXMLHash generate extra hidden characters which I cannot see them in console. When I try to use the AutoLayout Constraint String, It crash.

Here's the console log:

H:|-15-[title]-15-|

                   ^'

My XML seems right. And I have no idea how to fix it. Is it a problem from my XML doc? Or is it a parsing error which can be solved by SWXMLHash? I need help.

Thank you again!

Interleaving XML elements support

Hi David,

Thanks for the library, I like the API of this library but have one feature request (or bug report?) on it.

In some XML documents, elements with the same name can appear in any order instead of appear continuously. For example, an XHTML document:

<html>
  <body>
    <p>one</p>
    <div>two</div>
    <p>three</p>
    <div>four</div>
  </body>
</html>

As you can see, tag p and tag div can interleave. And to parse and render this XHTML correctly, all the elements order in this document should be kept. So one-two-three-four should be shown in the browser instead of one-three-two-four. However, this seems not possible in current implementation.

Right now, in current implementation, all child elements are stored in an ordered dictionary, whose key is the element name and value is an array of elements with the same element name. When adding an element, the new element will be appended to the dictionary entry with the element name, and when retrieving all children, the entire dictionary will be iterated entry by entry.

Is there any plan to support the XML document with interleaving pattern like above? The current implementation seems to me incorrect when handling such interleaving pattern by giving me incorrect elements order because it will groups elements by their names first.

To support this interleaving pattern, we could simply use an array to replace the ordered dictionary, and this will not only make the implementation correct (XML document is essentially a linear document I think) but also much simpler. The only down side is the subscript access by element name will be slower but that may be acceptable. What do you think?

add .all to documentation

Took me a few reads to figure out that xml["root"]["catalog"]["book"].all would retrieve "all books under catalog in an array". Maybe I'm dumb.

This is a great tool, thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.