swiftdocorg / markup Goto Github PK
View Code? Open in Web Editor NEWA Swift package for working with HTML, XML, and other markup languages, based on libxml2.
License: MIT License
A Swift package for working with HTML, XML, and other markup languages, based on libxml2.
License: MIT License
I'm seeing pointer being freed was not allocated
sometimes when trying to set attribute. In particular when trying to set attribute that's been removed from document and added to fragment like this:
let xml = #"""
<item>
<item a="1"/>
</item>
"""#
let document = try XML.Document(string: xml)!
let three = document.search(xpath: "//*[@a=\"1\"]").first!
three.remove()
let fragment = DocumentFragment(children: { three })
three["a"] = "8"
I can avoid the crash if I create the document fragment like this instead:
let xmlDoc = document.rawValue.bindMemory(to: _xmlDoc.self, capacity: 1)
let fragment = DocumentFragment(rawValue: xmlNewDocFragment(xmlDoc))!
I guess it's bad to move and xml node belonging to a document to another node that doesn't belong to a document? Please let me know if you have a better idea of what's wrong and why the fix works.
I have a MusicXML document, in part-wise format, and I want to loop over all notes for each part.
<part id="P1">
<measure number="1">
<note>
<pitch>
<step>A</step>
</pitch>
</note>
</measure>
<measure number="2">
<note>
<pitch>
<step>B</step>
</pitch>
</note>
</measure>
<measure number="3">
<note>
<pitch>
<step>C</step>
</pitch>
</note>
</measure>
</part>
<part id="P2">
<measure number="1">
<note>
<pitch>
<step>D</step>
</pitch>
</note>
</measure>
<measure number="2">
<note>
<pitch>
<step>E</step>
</pitch>
</note>
</measure>
<measure number="3">
<note>
<pitch>
<step>F</step>
</pitch>
</note>
</measure>
</part>
when that document is loaded, and the following code is executed
for part in document!.search(xpath: "//part") {
debugPrint("Part:",part["id"] ?? "no part id found")
for measure in part.search(xpath: "//measure") {
var notes = ""
for step in measure.search(xpath: "//step") {
notes += step.text
}
debugPrint(notes)
}
}
my expectation would be to get something like:
Part 1
ABC
Part 2
DEF
Instead I get
Part 1
ABCDEF
Part 2
ABCDEF
I know this lib isn't advertised as ready for production, but I've been having fun using it in a side project.
I've also been making some fixes as I run into issues:
In my current use it seems the parsed libxml2 structures are never freed. I see that it's not as simple as calling xmlFree upon deinit of swift object since the xmlPtr's are not tied to swift object lifetimes. I'm unsure of best way to solve.
Do you have a memory management design in mind so that libxml2 structures are freed?
In support of @compnerd's work to get swift-doc
working on Windows.
Thanks for starting this!
Is there a reason that Element.clone() isn't public? Can it be made public?
Thanks,
Jesse
I am using Xcode 12.5 on M1 Mac Big Sur 11.4 with swift 5.4
And after add this package, it gives the following error message
It seems that I did not have libxml2 setup properly, but the README says If you're on Linux or if you're on macOS and using Xcode < 11.4
.
Anyway I install libxml2 using brew and try to force link it to fix this problem
$ brew install libxml2
$ brew link --force libxml2
But brew refused to do so
Warning: Refusing to link macOS provided/shadowed software: libxml2
If you need to have libxml2 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/libxml2/bin:$PATH"' >> ~/.zshrc
For compilers to find libxml2 you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/libxml2/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libxml2/include"
For pkg-config to find libxml2 you may need to set:
export PKG_CONFIG_PATH="/opt/homebrew/opt/libxml2/lib/pkgconfig"
So how can I solve this problem?
Is there a reason why this method isn't named add
?
public func insert(child node: Node) {
xmlAddChild(xmlNode, node.xmlNode)
}
The underlying API uses the term 'add'. To me insert
means the method should take an index, or maybe the node will be put in the front of the children list.
Hi i simply wanted to tell you that I find really useful what you are doing.
I am writing an app to process MusicXML format, and was really puzzling on how to proceed...
Thanks to your code I could very rapidly load the files and start doing the analysis I want, without investing any time in the very tedious XML parsing task..
It would be amazing when the XSLT support will be available .
Onnce you get to version 1.0 will be happy to write a tutorial / story on using your library for music .
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.