Join Gini von Courter for an in-depth discussion in this video Using the XML Web Part, part of SharePoint Designer 2013: Creating Data-Driven Sites.
- In the same way that I can use the rss web part to bring in an rss feed, there is an xml web part that I can use as well. So let's create a new page. Predictably, I'm going to call this xmlsample. Here's my blank page open for editing. I'd like to insert a web part from content roll up, and it's the xml viewer. Now notice that this transforms xml data using xsl, and shows the results. That's its description. When we created a data source from xml, all we used was an xml file.
I'll show you what that looks like when we use this xml web part. I'll show you what it looks like when we only pay attention to the xml file with the xml viewer web part. Let me go ahead and add this. Open the tool pane. I'll be prompted to save this, and I'll say OK. It would like to know where my xml file is. So I need to have that file some place here. You'll remember that we loaded that earlier. This is a builder, so I can enter information about it, but what I really need to do is go to my documents and find it. So I'm going to open my document library in a new tab, and here is my books.
I'm going to click the menu and say I'd like to find its properties. Notice that this is a hyperlink. If I point to it, notice at the bottom left corner of the screen, it tells me what the shortcut here is, but that's the shortcut I want. I'm going to copy this. Go back and I'm going to paste this right here and test the link. What the link should do is try to take me right to that page, and that's what it's trying to do, that's great. So we have an xml link here, and I'm going to say OK. Let's see how our xml looks.
It looks like one big text block. That's because there's nothing to style it. This is basically a text dump. If I want my xml to look better than this, to look like a table, I have to take charge of presenting this as a table. Unlike the rss feed, I'm getting very little in terms of styling, there's nothing here by default. So this is column after column of data. There are two pieces to this. The first is this is our current books.xml document. It starts by saying xml version one and then the data starts.
If I want to call out a style sheet, normally what I'll have is I'll have a reference to it right here following xml versioning. So I want to modify my books file, and I also want to have an xsl file, a style sheet to go along with it. To do that, I'm going to open another application called notepad-plus-plus. Notepad-plus-plus is a free editor that you can use for xml and all of the other types of files that you'll use. You really don't need to know a lot about xml to be able to be fairly effective with it.
So if you're going to learn one additional new thing that you'd like that's a little bit of coding, xml would be a good choice. Here's a free tool that you can use to work with it. I'm going to switch over to notepad-plus-plus and show you the modified file and the xsl file. I created a new version of books. It's called books2cxsl.xml. Don't worry about the name. I'll need to know it in a moment. Notice that the second line says there's a style sheet and that its name is books2.xsl.
Let me show you what the style sheet looks like because that's the only difference in this file. In the style sheet, it also is an xml document. It provides information that says we're going to use the Arial font, that after we've listed a title of the book that we're going to put a comma and have the word author and a colon, and then it's going to show author information, that it's going to format genre and it's going to put that in parentheses. Here's the open parentheses, put the genre in and the close parentheses.
In each of these cases, we're going to apply a particular template to the text itself. We're going to have the title in bold. Here's an open and close on the bold. We're going to have italicized genres. We're going to do the author's name in green. All of it will be in Arial. If you're interested in learning more about xml, check out XML Essential Training. So I'm going to upload those two files that I created so that I have them available to me in SharePoint. I've returned to my documents library.
I'd like books2xsl and books2cxsl.xml. I'm just going to drag those in and upload them both. That shouldn't take long at all, and it doesn't. Notice that books2 has a slightly different settings type of an icon on it because it's a style sheet. Now let's go back and modify our xml viewer. Rather than using books.xml, I'm going to use books2cxsl.xml.
I'm going to test that link and make sure that works. It says do you want to open it? Yep. That worked fine. Now I want to assign the xsl editor. I can click and if I've copied xsl, I can just paste it right in here, or I can link to an xsl file that is on our site. Now it's going to be very similar to this link. I'm going to just copy this, paste it. Notice that I don't need to have httpskinetico.sharepoint.com, etc. It knows that it's looking right here, and it's books2.xsl, or a style sheet for xml.
I'm going to say OK, test the link. It says do you want to open this? It can find the file, that's fine. I'll say OK. Now with the style sheet applied, that's the only difference is I've added an xsl file, and this now is what our xml viewer is returning. I'm going to go ahead and overwrite the page. It says I'm editing this page. Clearly am I, I'm right here. That's the use of the xml viewer web part. It's a little complex to go through all the pieces, but once you've done it two or three times, you're going to be very, very fast with this. So don't be afraid to use the xml viewer web part, or for that matter, to use the rss viewer web part, and to apply xsl to be able to style how you want this information to appear in the web part itself.
- Managing data sources
- Displaying external data with RSS, XML, and Data View Web Parts
- Using Business Connectivity Services
- Creating data-driven pages
- Enhancing data presentation
- Filtering data
- Displaying associated lists