Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XML Schema Import

XML Schema Import

Scheduled Pinned Locked Moved XML / XSL
xmldatabasecomregexquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jason Weibel
    wrote on last edited by
    #1

    I am attempting to create a generic xml schema file that defines element type restrictions. That file is then imported into my additional xml schemas, which make use of the defined types. Here is what I have. General Formatting File <?xml version="1.0" encoding="utf-8" ?> <xs:schema id="GeneralFormatting" targetNamespace="http://localhost/XMLWebServices/GeneralFormatting.xsd" elementFormDefault="qualified" xmlns:gns="http://localhost/XMLWebServices/GeneralFormatting.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- Define format restriction --> <xs:simpleType name="UserName"> <xs:restriction base="xs:string"> <xs:pattern value="([a-zA-Z0-9])*"></xs:pattern> <xs:whiteSpace value="preserve" /> </xs:restriction> </xs:simpleType> </xs:schema> XML Schema <?xml version="1.0" encoding="utf-8" ?> <xs:schema id="WTNManagement_XSD" targetNamespace="http://localhost/XMLWebServices/Management.xsd" elementFormDefault="qualified" xmlns:tns="http://localhost/XMLWebServices/Management.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:import namespace="http://localhost/XMLWebServices/GeneralFormatting.xsd" schemaLocation="http://localhost/XMLWebServices/GeneralFormatting.xsd" /> <!-- definition of elements --> <xs:element name="Management" id="Management"> <xs:complexType> <xs:sequence> <!-- File Sequence number, must be unique --> <xs:element name="SeqNum" type="xs:integer" /> <!-- User making request --> <xs:element name="UserName" type="xs:UserName" /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> This code isn't working could someone point me in the right direction. Thanks Jason W.

    R 1 Reply Last reply
    0
    • J Jason Weibel

      I am attempting to create a generic xml schema file that defines element type restrictions. That file is then imported into my additional xml schemas, which make use of the defined types. Here is what I have. General Formatting File <?xml version="1.0" encoding="utf-8" ?> <xs:schema id="GeneralFormatting" targetNamespace="http://localhost/XMLWebServices/GeneralFormatting.xsd" elementFormDefault="qualified" xmlns:gns="http://localhost/XMLWebServices/GeneralFormatting.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- Define format restriction --> <xs:simpleType name="UserName"> <xs:restriction base="xs:string"> <xs:pattern value="([a-zA-Z0-9])*"></xs:pattern> <xs:whiteSpace value="preserve" /> </xs:restriction> </xs:simpleType> </xs:schema> XML Schema <?xml version="1.0" encoding="utf-8" ?> <xs:schema id="WTNManagement_XSD" targetNamespace="http://localhost/XMLWebServices/Management.xsd" elementFormDefault="qualified" xmlns:tns="http://localhost/XMLWebServices/Management.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:import namespace="http://localhost/XMLWebServices/GeneralFormatting.xsd" schemaLocation="http://localhost/XMLWebServices/GeneralFormatting.xsd" /> <!-- definition of elements --> <xs:element name="Management" id="Management"> <xs:complexType> <xs:sequence> <!-- File Sequence number, must be unique --> <xs:element name="SeqNum" type="xs:integer" /> <!-- User making request --> <xs:element name="UserName" type="xs:UserName" /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> This code isn't working could someone point me in the right direction. Thanks Jason W.

      R Offline
      R Offline
      Retsof Nawor
      wrote on last edited by
      #2

      You shouldn't be using the xs: prefix for the UserName type in the second schema, as the xs is for the schema namespace. You probably should define another xmlns for the imported namespace ie xmlns:gf="http:....GeneralFormatting.xsd" and then have

      J 2 Replies Last reply
      0
      • R Retsof Nawor

        You shouldn't be using the xs: prefix for the UserName type in the second schema, as the xs is for the schema namespace. You probably should define another xmlns for the imported namespace ie xmlns:gf="http:....GeneralFormatting.xsd" and then have

        J Offline
        J Offline
        Jason Weibel
        wrote on last edited by
        #3

        Something like this? Generic Formatting XML Schema <?xml version="1.0" encoding="utf-8" ?> <xs:schema id="GeneralFormatting" targetNamespace="http://localhost/XMLWebServices/GeneralFormatting.xsd" elementFormDefault="qualified" xmlns:ns="http://localhost/XMLWebServices/GeneralFormatting.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- Define format restriction --> <xs:simpleType name="UserName"> <xs:restriction base="xs:string"> <xs:pattern value="([a-zA-Z0-9])*"></xs:pattern> <xs:whiteSpace value="preserve" /> </xs:restriction> </xs:simpleType> </xs:schema> Additional XML Schema <?xml version="1.0" encoding="utf-8" ?> <xs:schema id="WTNManagement_XSD" targetNamespace="http://localhost/XMLWebServices/Management.xsd" elementFormDefault="qualified" xmlns:tns="http://localhost/XMLWebServices/Management.xsd" xmlns:gns="http://localhost/XMLWebServices/GeneralFormatting.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:import schemaLocation="http://localhost/XMLWebServices/GeneralFormatting.xsd" /> <!-- definition of elements --> <xs:element name="Management" id="Management"> <xs:complexType> <xs:sequence> <!-- File Sequence number, must be unique --> <xs:element name="SeqNum" type="xs:integer" /> <!-- User making request --> <xs:element name="UserName" type="gns:UserName" /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> Thanks Jason W.

        1 Reply Last reply
        0
        • R Retsof Nawor

          You shouldn't be using the xs: prefix for the UserName type in the second schema, as the xs is for the schema namespace. You probably should define another xmlns for the imported namespace ie xmlns:gf="http:....GeneralFormatting.xsd" and then have

          J Offline
          J Offline
          Jason Weibel
          wrote on last edited by
          #4

          Here are the details of the error message I’m getting. Type ‘http://localhost/XMLWebServices/GeneralFormatting.xsd:UserName’ is not declared. An error occurred at ... Hope that helps. Jason W.

          R 1 Reply Last reply
          0
          • J Jason Weibel

            Here are the details of the error message I’m getting. Type ‘http://localhost/XMLWebServices/GeneralFormatting.xsd:UserName’ is not declared. An error occurred at ... Hope that helps. Jason W.

            R Offline
            R Offline
            Retsof Nawor
            wrote on last edited by
            #5

            In your first schema you should change the xmlns:gns="http://localhost/XMLWebServices/GeneralFormatting.xsd" to xmlns="http://localhost/XMLWebServices/GeneralFormatting.xsd" so that all types declared are in that namespace, otherwise you would have to put the gns prefix on all type names...

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups