I'm generating sitemaps and their index with JDOM2.
what I'd like to obtain is this:
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>http://
so I added an attribute to the root element titled "xmlns". Running the code I receive this error:
The name "xmlns" is not legal for JDOM/XML attributes: An Attribute name may not be "xmlns"; use the Namespace class to manage namespaces.
How can I obtain what I need without changing the above structure?
thanks!
You need to use namespaces, not attributes:
Element root = new Element("sitemapindex", "http://www.sitemaps.org/schemas/sitemap/0.9");
Read up on namespaces....: http://www.w3schools.com/xml/xml_namespaces.asp
Rolf
Related
I want to get the Maximum value of <ID> from all the documents present inside the database.
Sample Document-
<root xmlns="http://marklogic.com/sample">
<node>
<ID>3253523</ID>
<value1>.....</value1>
<value2>.....</value2>
<value3>.....</value3>
<value4>.....</value4>
.....................
</node>
</root>
The approach which i tried is as below-
I created a path namespace with prefix sa with uri http://marklogic.com/sample.
Created a path range index of type int with path as /sa:root/sa:node/sa:ID
3.Trying to fetch the maximum value from the database by using the below code-
declare namespace sa = "http://marklogic.com/sample";
(cts:values(cts:path-reference('/sa:root/sa:node/sa:ID'), (), "descending"))[1]
But this is giving me an empty sequence. Not sure what i am missing here.
Any Suggestions ??
Try passing a map with the namespace bindings as the third argument to cts:path-reference(). See: http://docs.marklogic.com/cts:path-reference
By the way, cts:max() will probably be the most efficient way to get the maximum value from a range index. See: http://docs.marklogic.com/cts:max
The approach would resemble the following fragment:
cts:max(
cts:path-reference('/sa:root/sa:node/sa:ID', (),
map:entry("sa", "http://marklogic.com/sample")
))
Hoping that helps,
As suggested by Elijah Bernstein-Cooper
I just added the xmlns="http://marklogic.com/sample" namespace in the xml shared by you and inserted few xml files in the db.
Created the path namespace, path range index and ran the shared cts query and it worked perfectly so Elijah is correct you just need to specify the namespace in the xml.
Small change in your query is in declare namespace statement, prefix will be sa not es.
hope this helps.
===Update: Using org.reflections:reflections:0.9.11
Looking to use the following line to pull a list of class names from Kotlin source...
Reflections.getSubTypesOf(Any::class.java)
However I receive a message that Kotlin class files aren't being seen when I run the following script...
val classLoader = URLClassLoader(this.getDirectoryUrls(), null)
println("retrieved class loader")
val config = getConfig(classLoader)
println("retrieved source config")
val reflections = Reflections(config)
println("retrieved reflections")
// For 3 paths: Reflections took 3 ms to scan 3 urls, producing 0 keys and 0 values
=== Update: The 3 urls added by "getDirectoryUrls()" are directories containing kotlin class source files.
Below is my config... ideas?
private fun getConfig(classLoader: ClassLoader): ConfigurationBuilder {
val config = ConfigurationBuilder().setUrls(ClasspathHelper.forClassLoader(classLoader))
// .setScanners(SubTypesScanner(false), ResourcesScanner())
if (!packagePath.isNullOrBlank()){
System.out.println("looking in package [$packagePath]")
config.filterInputsBy(FilterBuilder().include(FilterBuilder.prefix(packagePath)))
}
config.addClassLoader(classLoader)
config.setScanners(SubTypesScanner(), TypeAnnotationsScanner())
return config
}
Setting SubTypesScanner(false) seems to be required to get any types with getSubTypesOf(Any::class.java) (that parameter itself stands for excludeObjectClass). Looking at the bytecode of Kotlin classes you immediately see, that they are actually looking the same as Java classes. There is no Any-superclass there. Note that Kotlins Any is actually also in other means very similar to Javas Object (but not the same, check also the following answer to 'does Any == Object'). So, we need to include the Object-class when scanning for subtypes of Any (i.e. excludeObjectClass=false).
Another problem could be the setup of your URL array. I just used the following to setup the reflections util:
val reflections = Reflections(ConfigurationBuilder()
.addUrls(ClasspathHelper.forPackage("my.test.package"))
.setScanners(TypeAnnotationsScanner(), SubTypesScanner(false)))
which will resolve all matching subtypes and will return subtypes also for Any.
reflections.getSubTypesOf(MyCustomSuperType::class.java).forEach(::println)
reflections.getSubTypesOf(Any::class.java).forEach(::println)
Analysing further: you mention "Kotlin class source files"... if that means you are pointing to the directory containing the .kt-files, then that is probably your problem. Try to use the directory which contains the .class-files instead. Moreover, ensure that the classes are on the classpath.
Maybe you know already, maybe not? Note also that if you have a (classes) directory, say /sample/directory, which is on the classpath and which contains a package, say org.example (which corresponds to the folder structure org/example or full path /sample/directory/org/example) then you must ensure that you add an URL similar to the following:
YourClass::class.java.classLoader.getResource("")
and not:
YourClass::class.java.classLoader.getResource("org.example")
// nor:
YourClass::class.java.classLoader.getResource("org/example")
You basically require the "base" directory (in the example /sample/directory or from the view of the classloader just "")) where to lookup the packages and not the package itself. If you would supply one of the latter URLs, only classes that are in the default package (within /sample/directory/org/example) would actually be found, which however is a rather uncommon setup.
OK, so I've managed to create a custom project flavor with a custom property page. It all works and the values are being saved to the .csproj file like such:
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{880389B4-B814-4796-844B-F0E1678C31D1}" Configuration="Debug|Any CPU">
<ServiceLibraryProjectFlavorCfg>
<BooleanProperty>True</BooleanProperty>
</ServiceLibraryProjectFlavorCfg>
</FlavorProperties>
<FlavorProperties GUID="{880389B4-B814-4796-844B-F0E1678C31D1}" Configuration="Release|Any CPU">
<ServiceLibraryProjectFlavorCfg />
</FlavorProperties>
</VisualStudio>
What I cant seem to figure out is how to access this custom property from, say, a menu item callback in my package. I can get the project that the selected item in the solution explorer which was right clicked belongs to, but I'm stuck after that...
Any help will be appreciated
Thanx
Hein
OK, I figured it out.
As part of creating a custom project flavor, you inherit from FlavoredProjectBase and implement the IVsProjectFlavorCfgProvider interface.
the IVsProjectFlavorCfgProvider has one implementable method
int CreateProjectFlavorCfg(IVsCfg pBaseProjectCfg, out IVsProjectFlavorCfg ppFlavorCfg)
So here I implemented a static mapping between my custom IVsProjectFlavorCfg and the specified IVsCfg
Already having a EnvDTE.Project reference, I could then use the following to get a IVsCfg reference:
IVsHierarchy hierarchy1 = null;
var sol = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution;
sol.GetProjectOfUniqueName(project.UniqueName, out hierarchy1);
IVsSolutionBuildManager bm = Package.GetGlobalService(typeof(IVsSolutionBuildManager)) as IVsSolutionBuildManager;
IVsProjectCfg[] cfgs = new IVsProjectCfg[1];
bm.FindActiveProjectCfg(IntPtr.Zero, IntPtr.Zero, hierarchy1, cfgs);
IVsCfg cfg = cfgs[0] as IVsCfg;
I could then use the IVsCfg reference to look up my custom configuration provider.
If you can access the project node instance (and if your project system is based on MPF), you can just use the GetProjectProperty method of the ProjectNode class. It obtains a ProjectPropertyInstance and returns its evaluated value, or null if the property does not exist.
I'm trying to add custom metadata namespace to CQ DAM.
I. e. URI http://example.com/ with prefix ex
added namespace in /crx/explorer/nodetypes/index.jsp in Namespaces tab
added line <ex = 'http://example.com/'> in /libs/dam/nodetypes/dam.cnd
created /libs/dam/options/metadata/ex folder
then I can't set metadata property to the /libs/dam/options/metadata/ex folder, nor add any subnode to it. ("No matching property definition found" error).
What is the full procedure of adding custom metadata namespace in CQ DAM?
Two first steps are alternative ways of doing the same thing.
The created /libs/dam/options/metadata/ex folder should by
sling:Folder not nt:Folder
I have created a configuration section designer project to represent nodes of a custom section necessary to read and save from my web application. I am able to successfully create instances of the configuration elements and collections, however when I save the configuration using the referenced System.Configuration.Configuration object and issuing save, the elements get merged into their parents as attributes. An example of the issue is outlined below:
After calling the referenced Configuration.save, the output is as follows:
<savedReports xmlns="SavedReportSchema.xsd">
<resultsSets dataViewId="1" id="4203bb88-b0c4-4d57-8708-18e48f0a1d2d">
<selects keyId="1" sortOrder="1" />
</resultsSets>
</savedReports>
As defined in my configuration section designer project (confirmed by the resulting xsd as well) the output should match the following:
<savedReports xmlns="SavedReportSchema.xsd">
<resultsSets>
<savedReport id="1">
<selects>
<select keyId="1" sortOrder="1"/>
</selects>
</savedReport>
</resultsSets>
</savedReports>
Any ideas? The element collection types are set to BasicMapAlternate however when I set them to AddRemoveClearMapAlternate they are not merged but they are prefixed by "add" rather than "select" or "savedReport" causing the validation to be off.
Turns out AddRemoveClearMapAlternate was the option I needed to correct my problem referenced in the question.