Jump to content

Assistance with querying an XML Document


lee.sydenham@bllaw.co.uk

Recommended Posts

I am a Systems Administrator and am new to XML so looking for some assistance if possible please.The problem I am trying to solve is with folder permissions in file structures.I have written a small script which will loop through a folder structure and create an xml file containing all folder names in the tree and the permissions assigned to each, e.g:<RootFolder> <Folder name=""> <Permissions> <Acl></Acl> <Acl></Acl> ... </Permissions> <Folder name=""> <Permissions> <Acl></Acl> <Acl></Acl> ... </Permissions> <Folder name=""> </Folder> ... </Folder> <Folder name=""> ... </Folder> ... </Folder></RootFolder>Given this XML I would like to construct a query to display the folder name if the permissions of a folder are different to the permissions of its parent. Can anyone advise if this is possible and how I might go about doing it?Thanks,Lee.

Link to comment
Share on other sites

It really depends on what language you plan to use to query the XML with. I'm not sure I understand the idea either. Could you fill up the above sample with some data, also giving some possible desired output?

Link to comment
Share on other sites

OK, sorry I did not explain myself better.Some sample data is:<RootFolder> <Folder name="C:\TestFolder1"> <Permissions> <Acl>Administrators:FullControl</Acl> <Acl>Users:Modify</Acl> </Permissions> <Folder name="C:\TestFolder1\SubFolder1"> <Permissions> <Acl>Administrators:FullControl</Acl> <Acl>Users:Modify</Acl> ... </Permissions> <Folder name="C:\TestFolder1\SubFolder1\2ndLevel1"> <Permissions> <Acl>Administrators:FullControl</Acl> <Acl>SpecificGroup:FullControl</Acl) </Permissions> </Folder> ... </Folder> <Folder name="C:\TestFolder1\SubFolder2"> ... </Folder> ... </Folder></RootFolder>From above, SubFolder1 and SubFolder2 have the same set of permissions as their parent, C:\TestFolder1 so I am not interested in output here. I am interested in displaying folders that do not have the same permissions as their parent, as in "C:\TestFolder1\SubFolder1\2ndLevel1", in which Users have been removed and permissions granted to a specific groupI hope that this clarifies what I am trying to achieve. I generally use VBScript for my scripting (simple SysAdmin scripting) but not sure XML-wise and am open to suggestions.Thanks,Lee.

Link to comment
Share on other sites

Hi, why you are writing a script in XML, Better you write a template in VTL (Velocity Template Language) its just like any script and very simple even a child can use and more flexible for operation like you have asked. Output of template file will be XML file which u require. VTL is project of Apache Tomcat you can go through web-site.you have to do-A java(class) file to manipulate with file permissions -> template -> XML (output)Advantage it will dynamic and platform independent, while if you use Xquery it depends which providers u r using, as little deviation in Xquery vendors.

Link to comment
Share on other sites

@Ashvini, uh... what? More info please. I'm interested in the "what"... "What is it? What does it need?" and the why... "Why is it thought to be platform independant" and "Why is better?".I spend some time on it (shame on me :) ) and I figured out the problem that was stopping me... white space... damn it! It's one of the most frequent XML problems to deal with. Anyhow, the XPath expression:

//Folder[Permissions and Permissions != ../Permissions]

will work, but you'll have to find some platform dependant way of removing the whitespace from the Permissions elements first or all elements altogether. It's easy in XSLT:

<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	<xsl:output indent="yes"/>	<xsl:strip-space elements="*"/>	<xsl:template match="/">	<RootFolder>		<xsl:copy-of select="//Folder[Permissions and Permissions != ../Permissions]"/>	</RootFolder>	</xsl:template></xsl:stylesheet>

I'm not sure about the way to remove whitespace text nodes in other languages.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...