locked
How to specify a relative path for the xsd file in the XML Source file? RRS feed

  • Question

  • I have one xml file called Layout.xml. and I have one schema file LayoutSchema.xsd.

    but the two files are in different disk path. then how should I associate the two files with relative path?

    for example, i can refer to the xsd file using the absolute path.

    <Layout xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.w3.org/2001/XMLSchema-instance D:\KCS-Client\Basic\Dev-China\Source\CommonPresentation\OperationDialogUI\Config\LayoutSchema.xsd">

    but my question is how i could refer to xsd file using relative path?

    • Moved by Sheng Jiang 蒋晟 Wednesday, September 14, 2011 3:59 AM English (From:Visual C#)
    Wednesday, September 14, 2011 3:11 AM

Answers

  • Well first of all the schemaLocation attribute is a list of pairs of URI references where the first item of each pair list the namespace name and the second item the location of the corresponding schema. Therefore doing

      xsi:schemaLocation="http://www.w3.org/2001/XMLSchema-instance

    does not make any sense at all, unless you want to provide a schema for the namespace http://www.w3.org/2001/XMLSchema-instance. So instead of http://www.w3.org/2001/XMLSchema-instance you need to list the targetNamespace of your schema. Then the second item needs to be a URI to the schema location, not a Windows file path. It can be a relative URI if you want so doing e.g.

      xsi:schemaLocation="http://example.com/ns1 ../../../../CommonPresentation/OperationDialogUI/Config/LayoutSchema.xsd"

    is certainly possible (where as pointed out earlier you need to replace http://example.com/ns1 with the targetNamespace URI of your schema).


    MVP Data Platform Development My blog
    Thursday, September 15, 2011 9:45 AM

All replies

  • You can simply use a relative URL e.g.

      xsi:schemaLocation="http://example.com/ns1 LayoutSchema.xsd"

    if the schema file and the instance document are in the same directory (and where of course http://example.com/ns should be replaced with the targetNamespace URI of your schema).

    Also note that anything you use should be a URL and not a Windows file path so make sure you use forward slashes.

    If you have different directories for instance document and schema document and you want to use a relative URL then do e.g.

      xsi:schemaLocation="http://example.com/ns1 ../../../CommonPresentation/OperationDialogUI/Config/LayoutSchema.xsd"

    where of course the path I have used is simply an example, I don't know your actual directory structure.


    MVP Data Platform Development My blog
    Wednesday, September 14, 2011 10:54 AM
  • Thanks for your information. but i want to know how the relative phisical path is configured in the xml file.

    let me put it this way. say, my lay xml file is in the directory:D:\Work\Basic\Dev-China\Source\DataAccess\ApplicationObjectMock\Layout\Layout.xml

    and i need one schema file which is in the directory:D:\Work\Basic\Dev-China\Source\CommonPresentation\OperationDialogUI\Config\LayoutSchema.xsd

    i wanna refer to the schema file in my layout.xml file with relative path.

    in my previous example, i referred to the schema file using absolute path,like this:

    <Layout xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.w3.org/2001/XMLSchema-instance D:\Work\Basic\Dev-China\Source\CommonPresentation\OperationDialogUI\Config\LayoutSchema.xsd">

    then, how can I refer to the schema file using relative path in my Layout.xml file.

     

    thanks.

     

    Thursday, September 15, 2011 1:28 AM
  • Well first of all the schemaLocation attribute is a list of pairs of URI references where the first item of each pair list the namespace name and the second item the location of the corresponding schema. Therefore doing

      xsi:schemaLocation="http://www.w3.org/2001/XMLSchema-instance

    does not make any sense at all, unless you want to provide a schema for the namespace http://www.w3.org/2001/XMLSchema-instance. So instead of http://www.w3.org/2001/XMLSchema-instance you need to list the targetNamespace of your schema. Then the second item needs to be a URI to the schema location, not a Windows file path. It can be a relative URI if you want so doing e.g.

      xsi:schemaLocation="http://example.com/ns1 ../../../../CommonPresentation/OperationDialogUI/Config/LayoutSchema.xsd"

    is certainly possible (where as pointed out earlier you need to replace http://example.com/ns1 with the targetNamespace URI of your schema).


    MVP Data Platform Development My blog
    Thursday, September 15, 2011 9:45 AM