Frage

Ich fürchte, es ist nicht möglich, aber noch nicht überall gefunden gesagt wird, unmöglich, entweder sein.

Ich möchte eine Reihe von Dateien innerhalb eines XML-Dokuments mit Wildcards enthalten. Wie folgt aus:

<?xml version="1.0" encoding="utf-8"?>
<mydocument>
  <!-- ... -->
  <xi:include href="*include.xml"/>
</mydocument>

Ich weiß, dass es nicht funktioniert, aber ich denke, es ist meine Absicht klar zum Ausdruck bringt. Gibt es einen Weg, um dieses?

zu erreichen

Edit:

Ich habe versucht, xpointer Attribut zu verwenden, konnte aber nicht damit es funktioniert.

War es hilfreich?

Lösung

Is it possible to use wildcards with XInclude tags?

No. The href denotes a URI, and these do not have a concept of wildcards.

Otherwise it would be possible to mirror the Google homepage by saying something like href="http://www.google.com/*".

Hint: File systems do also not have any concept of wildcards. Shells do. They do the heavy lifting of filling in the blanks for you when they parse a path and see a *. The underlying file system never gets to see the asterisk.

Andere Tipps

There is a quick option

Override XmlResolver to create a Wildcard Aware Resolver:

class WildCardResolver : XmlUrlResolver
{
    public override Uri ResolveUri(Uri baseUri, string relativeUri)
    {
        try
        {
            DirectoryInfo di = new DirectoryInfo(baseUri.AbsolutePath); // TODO Check it is valid.
            string combinedFilePath = Path.GetTempFileName();
            using (FileStream combinedStream = new FileStream(combinedFilePath, FileMode.OpenOrCreate))
            {
                foreach (FileInfo fi in di.GetFiles(relativeUri))
                {
                    using (FileStream fileStream = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read))
                    {
                        fileStream.CopyTo(combinedStream);
                    }
                }
            }
            Uri absUri = new Uri(combinedFilePath);
            return absUri;
        }
        catch(Exception ex)
        {
            //Log Exception
            return base.ResolveUri(baseUri, relativeUri);
        }
    }
}

There is a lot to do to notice if Wildcards are applicable at all

Additionally, the BaseURI can be tricky because lets say the Source XML is from

file://c:/myXMLRepository/myXML.xml

includes *inc.xml

now the base URI is file//c:/temp/tmpA0.tmp

.

.

wish you best of luck,

EDIT:

Theres another way to override

public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)

but there are other problem imposed by that... because the Absolute URI will not always be valid, and the XIncludingReader try and verify it.

@Tomalek is absolutely right here. There are ways to do what you trying to do but XInclude is not the right answer. You are going to need some sort of tool that can handle wildcard expansion for you.

You can almost certainly do this with something like Norm Walsh's XProc implementation - calabash but you would need to roll your own equivalent to XInclude in some way.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top