I wanted to expose the result of a views as only a fragment of an XML. I did this by adding a display plugin of my own that didn't wrap the output of Views XML in HTML and by selecting "Views API mode" - but I also needed to be able to remove the doctype and some of the wrapping tags.
Attached is a patch that adds an option to remove the doctype as well as hides the root element and top-level child element if they are empty.
With Views XML patched this way you can do some pretty insanse stuff with it and Views Field View…
(I would btw suggest that you add some kind of display plugin that can Views XML can be paired with - either a super easy one that just removes all wrapping HTML or one that adds parts of the stuff that's now in the Views XML style plugin.)
Comments
Comment #1
patcon CreditAttribution: patcon commentedI always seem to catch you around, Pelle...! Overlapping interests I suppose. Awesome share, by the way. I'll let you know if I build anything cool with it :)
Comment #2
jvanhoose CreditAttribution: jvanhoose commentedI am working on a project which would be greatly benefited by using the "view in view" and this xml fragment patch (I need to dynamically generate a somewhat complex XML document). I installed the patch, and it seemed to work just fine the first time (the menu option showed up to enable "xml fragment" - and it worked properly). The next time, however, it not only didn't work - but the menu option appears to have disappeared.
I am certain that this is just something I am doing stupidly - but, any insight would be greatly appreciated.
Comment #3
patcon CreditAttribution: patcon commentedSorry if this is stupid suggestion, but if it was working and then suddently wasn't, then perhaps it's a site cache issue? Try clearing
Comment #4
obrienmd CreditAttribution: obrienmd commentedsub
Comment #5
gMaximus CreditAttribution: gMaximus commentedHi,
Thanks for sharing this awesome patch. I'm currently trying to build a video sitemap of my "media: youtube" embeds using your patch and other suggestions. However, as you say i need:
I was really hoping that you may be able to point me in the right direction... :) Without out that, my parent view with the page display "video-sitemap.xml" doesn't come out as an xml file...
This patch was my first, so i feel like I've climbed a mountain to get this close... lol
Would really appreciate any help,
Guy
Comment #6
voxpelli CreditAttribution: voxpelli commented@guyd: I apparently never pushed it to Drupal.org, but here is what I remember that I used: https://github.com/voxpelli/drupal-plain-views Feel free to fork and commit to Drupal.org or whatever you like - I'm likely not going to do any more work on it myself :/
Comment #7
gMaximus CreditAttribution: gMaximus commentedThanks a million for the lead. It was my birthday yesterday, so great timing :).. I'll investigate it fully in the week.... Here's the post i've made fyi:
http://drupal.org/node/1472776
Bye for now,
Guy
Comment #8
gMaximus CreditAttribution: gMaximus commentedJust finished making my video sitemap, thanks in large part to you... Just wanted to say thanks again :)
Comment #9
cornelyus CreditAttribution: cornelyus commentedWould this work for Drupal 7?
Thank you
Comment #10
iamfredrik CreditAttribution: iamfredrik commentedI made a patch for D7. The patch seems to work, but I haven't figured out how to get it to play nicely with Views field view. Views field view seems to strip all xml tags.
Comment #11
andypostLooks module have no tests, then they are not needed
please replace tabs with spaces
Comment #12
andypostAlso the code sill works for 7.x
Comment #13
heshanlkRerolled the patch and here are few tips to make it work with Views Field View module.
Tips:
Comment #14
kenorb CreditAttribution: kenorb commentedRe-roll of #13 with 2 spaces instead of tabs and removed trailing spaces. And the right format for git repo.