renggli / dart-xml

Lightweight library for parsing, traversing, and transforming XML in Dart.
http://pub.dartlang.org/packages/xml
MIT License
223 stars 52 forks source link

I want some helping using this package. #95

Closed thechinkysight closed 4 years ago

thechinkysight commented 4 years ago

I have my XML like this

<link type="text/html" title="View on Feedbooks" rel="alternate" href="https://www.feedbooks.com/book/2936"/>
<link type="application/epub+zip" rel="http://opds-spec.org/acquisition" href="https://www.feedbooks.com/book/2936.epub"/>
<link type="image/jpeg" rel="http://opds-spec.org/image" href="https://covers.feedbooks.net/book/2936.jpg?size=large&amp;t=1549045871"/>
<link type="image/jpeg" rel="http://opds-spec.org/image/thumbnail" href="https://covers.feedbooks.net/book/2936.jpg?size=large&amp;t=1549045871"/>

Here I have multiple link elements, among them I want href="https://covers.feedbooks.net/book/2936.jpg?size=large&amp;t=1549045871" from this specific element <link type="image/jpeg" rel="http://opds-spec.org/image/thumbnail" href="https://covers.feedbooks.net/book/2936.jpg?size=large&amp;t=1549045871"/>

Can somebody help here ?

renggli commented 4 years ago

This is not a valid XML document, but you can parse it as a fragment (i.e. XmlDocumentFragment.parse(input)) and use the traversal/querying methods as described in the tutorial.

thechinkysight commented 4 years ago

This is the whole XML

<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:schema="http://schema.org/" xmlns="http://www.w3.org/2005/Atom">
<title>Romeo and Juliet</title>
<id>https://www.feedbooks.com/book/2936</id>
<author>
  <name>William Shakespeare</name>
  <uri>https://www.feedbooks.com/author/494</uri>
  <schema:birthDate>1564</schema:birthDate>
  <schema:deathDate>1616</schema:deathDate>
</author>
<published>2008-09-18T07:59:29Z</published>
<updated>2020-08-27T07:58:31Z</updated>
<dcterms:language>en</dcterms:language>
<dcterms:issued>1597</dcterms:issued>
<dcterms:publisher>Feedbooks</dcterms:publisher>
<category scheme="http://www.feedbooks.com/categories" label="Fiction" term="FBFIC000000"/>
<category scheme="http://www.feedbooks.com/categories" label="Drama" term="FBDRA000000"/>
<category scheme="http://www.feedbooks.com/categories" label="Romance" term="FBFIC027000"/>
<summary>Romeo and Juliet is a tragic play written early in the career of William Shakespeare about two teenage &quot;star-cross'd lovers&quot; whose untimely deaths ultimately unite their feuding households. It was among Shakespeare's most popular plays during his lifetime and, along with Hamlet, is one of his most frequently performed plays. Today, the title characters are regarded as archetypal &quot;young lovers&quot;. (From Wikipedia)</summary>
<dcterms:extent>25,496 words</dcterms:extent>
<dcterms:source>http://shakespeare.mit.edu</dcterms:source>
<link type="text/html" title="View on Feedbooks" rel="alternate" href="https://www.feedbooks.com/book/2936"/>
<link type="application/epub+zip" rel="http://opds-spec.org/acquisition" href="https://www.feedbooks.com/book/2936.epub"/>
<link type="image/jpeg" rel="http://opds-spec.org/image" href="https://covers.feedbooks.net/book/2936.jpg?size=large&amp;t=1549045871"/>
<link type="image/jpeg" rel="http://opds-spec.org/image/thumbnail" href="https://covers.feedbooks.net/book/2936.jpg?size=large&amp;t=1549045871"/>
<link type="application/atom+xml;profile=opds-catalog;kind=acquisition" title="From the same author" rel="http://www.feedbooks.com/opds/same_author" href="https://www.feedbooks.com/author/494/books/top.atom?lang=en"/>
<link type="application/atom+xml;profile=opds-catalog;kind=navigation" title="Categories for this book" rel="related" href="https://www.feedbooks.com/book/2936/categories.atom"/>
<link type="application/atom+xml;profile=opds-catalog;kind=navigation" title="Reading lists for this book" rel="related" href="https://www.feedbooks.com/book/2936/lists.atom"/>
<content type="html">&lt;p&gt;Romeo and Juliet is a tragic play written early in the career of William Shakespeare about two teenage &quot;star-cross'd lovers&quot; whose untimely deaths ultimately unite their feuding households. It was among Shakespeare's most popular plays during his lifetime and, along with Hamlet, is one of his most frequently performed plays. Today, the title characters are regarded as archetypal &quot;young lovers&quot;. (From Wikipedia)&lt;/p&gt;</content>
<link type="application/atom+xml;type=entry;profile=opds-catalog" rel="self" href="https://www.feedbooks.com/book/2936.atom"/>
  <link type="application/atom+xml" rel="contents" href="http://www.feedbooks.com/book/2936/contents.atom"/>
</entry>
thechinkysight commented 4 years ago

Your example helped me, thank you very much :D