I know I have seen this somewhere before, but I cannot find it again. I need an example of calling an xsd file from within another xsd. This is quite useful where a number for xml files are being generated, but where there is large common areas between these xml files being validated. In that scenario, it is useful to have an xsd that validates the parts common to all xml files, then have separate smaller xsd validation files for the parts of the xml that are specific to each xml file.
Thanks
I'd probably call it referencing another XSD file (calling implies that the XSD is run or executed in some way, which isn't the case).
In any case you are probably looking for either the import or the include elements, for example:
<?xml version="1.0"?>
<xs:schema elementFormDefault="qualified" targetNamespace="http://www.w3.org/2001/05/XMLInfoset" xmlns="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://www.example.com/IPO" />
<xs:include schemaLocation="example.xsd" />
</xs:schema>
What is the difference between import and include? Use import to reference declarations in a different namespace and include to reference declarations in the same namespace.
Related
I'm looking for a way to export table from excel to xml but every excel line should be different xml file, not as a default one xml file with all data.
So for example table like the one below:
This table should be exported into 3 xml files
first file 1.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<student-data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<record>
<TAGNAME1>mark</TAGNAME1>
<TAGNAME2>tom</TAGNAME2>
<TAGNAME3>london</TAGNAME3>
</record>
</student-data>
second file 2.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<student-data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<record>
<TAGNAME1>julie</TAGNAME1>
<TAGNAME2>jan</TAGNAME2>
<TAGNAME3>manchester</TAGNAME3>
</record>
</student-data>
etc...
Any ideas how to do that?
I've tried to use developer mode in excel with xml tab, but it export one file with all data.
Assuming you're using an XLSX file, you'll find it's actually a zip file. In its xl/worksheets subdirectory, the sheet1.xml and similarly named files (sheet2.xml, sheet3.xml, ...) represent the tabs that you see in the Excel file.
Typically, sheet1.xml will contain something like:
<worksheet...>
...
<sheetData>
<row r="1">
<c r="A1">...</c>
<c r="B1">...</c>
</row>
<row r="2">
<c r="A2">...</c>
<c r="B2">...</c>
</row>
</sheetData>
</worksheet>
Comparing that XML to what you see in Excel, you'll quickly spot the way a worksheet is encoded in XML. The <row><c/></row> structures almost immediately translate to what you need.
Strings are typically handled in a special way.
A cell with string contents usually contains a reference to a string value specified elsewhere. In the <c> element, the attribute t="s" indicates a referenced string. (the s attribute references a style id). The <v> element contains the string reference.
The zero-indexed reference list is stored in the xl/sharedStrings.xml file. Multiple occurrences of the same string will be stored more efficiently this way (instead of keeping them inline in the cells, which could result in multiple duplicates of the same string).
Using xmlstarlet and/or XSLT combined with some BaSH scripting for loops and handling file input and output, you could then get your desired result.
This is not an instant answer to what you want, but instead a nudge in the direction you could go. Your choice of tooling may vary. You'll learn useful things along the way. Learning curves may be steep but rewarding eventually. In the end, this will probably teach you more than any precooked answer.
I'm working on two large 3rd party schemas, one includes the other and generates a large number of type name collisions. If I could set the package on a namespace this problem would go away.
I hoped something like
<jaxb:bindings namespace="http://www.openapplications.org/oagis/9" >
<jaxb:schemaBindings>
<jaxb:package name="org.oagis" />
</jaxb:schemaBindings>
</jaxb:bindings>
would work, or perhaps
<jaxb:bindings node="/xsd:schema[#targetNamespace='http://www.openapplications.org/oagis/9']">
<jaxb:schemaBindings>
<jaxb:package name="org.oagis" />
</jaxb:schemaBindings>
</jaxb:bindings>
But no joy.
Trying to set on the individual xsd files in that namespace left me with the dread
[ERROR] Multiple <schemaBindings> are defined for the target namespace "http://www.openapplications.org/oagis/9"
Pointers/suggestions are appreciated.
This is a bit hard to answer without seeing the whole compilation. However I often got this error when compiling third-party schemas in the case when the same schema was included via different URLs.
I.e. I've implemented a project which compiled an extensive set of OGC Schemas. The problem was that these schemas referenced each other via relative and absolute URLs. So when I customized one of the schemas there were other schemas for the same namespace URI. Since JAXB processes imports and includes, it is not quite transparent what exactly gets compiled. Try to check your XJC logs for cues or - if you compile schemas directly via URLs (which is not recommended) - go through a logging proxy and see what actually gets accessed.
I have an xsd that I'm using to generate an object model in Java using JAXB and I want the Lists it generates to be renamed to xyzList instead of xyz. Is there a way to do this without having to add an entry in the bindings file for each list?
For example this xsd fragment:
<xs:element name="RegulatoryEL" minOccurs="0" maxOccurs="unbounded">
generates this:
protected List<RegulatoryEL> RegulatoryEL;
but I want something like:
protected List<RegulatoryEL> RegulatoryELList;
JAXB (JSR-222) does not provide a global setting to control how field/property names are generated for elements that can appear multiple times. Using standard config you will need to do this on a per element basis using an external binding file.
How do you customize how JAXB generates plural method names?
To do this in a more general way you could create your own XJC extension:
http://ricston.com/blog/xjc-plugin/
For manipulate names you can use plugin and register you own name converter. For example look at xjcnormalize.
Detailed explanation from their author you may find in this answer: JAXB convert non-ASCII characters to ASCII characters
I have a .xsd file and need to convert it to WSDL. How can I do that? Is converting it even the right approach? The .xsd file contains both request and response data.
You can not do that so easily. Usually, the xsd defines the structure (type) of the input and output messages. The wsdl used the xsd to define the operations that will be exposed by the service. An operation has usually a name and a pair of input and output messages.
I don't see how a tool could "reconstruct" the operations out of only the xsd only, except if it uses naming convention. E.g. messages requestDoIt and responseDoIt --> operation DoIt. If the xsd already contains the operations (which would be unusual) that could be ok, but it doesn't seem to be your case.
Manually creating the wsdl shouldn't be too long.
<types>
<xsd:schema xmlns="..." targetNamespace="...">
<xsd:import namespace="..." schemaLocation="MySchema.xsd"/>
</xsd:schema>
</types>
...
<wsdl:portType name="...">
<wsdl:operation name="doIt">
<wsdl:input message="tns:requestDoIt"/>
<wsdl:output message="tns:responseDoIt"/>
</wsdl:operation>
</wsdl:portType>
Have a look at WSDL essentials to get the general structure of the wsdl.
Or you can give a try to the tool WSDL Generator (from http://www.theprogrammerfactory.com/) whose purpose is apparently to ease this task. (Note that I never used it).
Another approach would be to generate classes out of the xsd, then use them to define the service class manually (this is the tedious part of matching types together into the corresponding operation) and then use another tool to transform the service class back into a complete wsdl. There are various tools available to convert to/from xsd and wsdl, for both Java or C#: wsgen, wsimport, xsd.exe, wsdl.exe.
Web Services Description Language Tool (Wsdl.exe)
I realized in C# "XMas XSD Schema Tool" to incorporate an XSD Schema structure into a WSDL file.
The WSDL file produced includes minimal structures to be used in a web service consumer tool.
If you want to try it for free, you have the manual and download link here: https://www.nick4name.eu/downloads/xmas_en/
Let me know your opinion.
I'm trying to wrap my head around xml schemas and one thing I'm trying to figure out is how to do relational type schemas where on element refers to another, possibly in another schema altogether. I've looked at the xsd:key and xsd:keyref and it seems like the sort of thing I'm interested in, but I'm not sure. Initially I just set attributes with the type xs:ID abd xs:IDREF, which obviously doesn't necessarily refer to a specific element as far as I could tell.
Basically, I have several different xml files where elements refer to other elements either in the same file or other files. It looks a lot like a relation database and I would love to use one, but the requirement is to only use XML files and so I'm at least trying to establish some sanity instead of just seemingly random strings relying on xml comments to define the relationships. It works for smaller projects, but it's certainly not scalable.
Any thoughts?
I'm not aware of anything within XML Schema that will allow you to validate multiple XML documents against one another. In the xs:id and xs:key (etc) constraints, you use xpath to apply the constraints. You can go to XML Schema Part 1: Structures and scroll down a little bit for the example to see these constraints in action.
If you have the ability to define a meta-XML file that includes your others (perhaps by entity references if by no other way) and then use a schema for that meta file, then you should be able to use XML Schema to apply your constraints. If you define a schema for each of your XML file types, you should be able to trivially (by xs:import or xs:include) define a meta-schema for an XML file that includes all of your XML content in one XML file. This meta-schema could successfully apply the constraints you want.
Let's say you have to validate a Wiki that has many posts, where each post has an author and maybe many comments where each comment also has an author, and that you have one XML file for all posts, one for all comments, one for all authors, and you want to validate constraints between these files, that each post uses authors and comments that exist, that each comment uses authors that exist, and so on. Let's say you have the following three files:
The file /home/username/posts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<posts>
<post>
<author name="author1"/>
<comment id="12345" pos="1"/>
<comment id="12346" pos="2"/>
<body>I really like my camera...</body>
</post>
...
</posts>
The file /home/username/comments.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<comments>
<comment id="12345" author="kindguy">
That was a very good post
</comment>
...
</comments>
The file /home/username/authors.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<authors>
<author name="kindguy" id="1"/>
<author name="author1" id="2"/>
...
</authors>
What I am suggesting is that you make a meta-XML file by using Entity References. For example, you could create the following XML file:
<?xml version="1.0" encoding="UTF-8" ?>
<!ENTITY postfile SYSTEM "file:///home/username/posts.xml">
<!ENTITY commentfile SYSTEM "file:///home/username/comments.xml">
<!ENTITY authorfile SYSTEM "file:///home/username/authors.xml">
<root>
&postfile1;
&commentfile;
&authorfile;
</root>
This meta-XML file (actually, a plain old XML file ... the "meta" is only from the perspective of your three defined XML files, and not in any XML sense) is the exact equivalent of the following file, and XML parsers will act as if you truly had the following file:
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<posts>
<post>
<author name="author1"/>
<comment id="12345" pos="1"/>
<comment id="12346" pos="2"/>
<body>I really like my camera...</body>
</post>
...
</posts>
<comments>
<comment id="12345" author="kindguy">
That was a very good post
</comment>
...
</comments>
<authors>
<author name="kindguy" id="1"/>
<author name="author1" id="2"/>
...
</authors>
</root>
From this file, you can define an XML schema that will apply the desired constraints, even though with the individual files there is no way to apply constraints. Since using XML entity notation you have "included" all the XML into one file, you can use xpath in the contraint references.
This issue is discussed in http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html note section 3.11.
If I remember correctly, xs:ID has to be globally unique within whole document, while xs:key only has to be unique for the element for which it was defined. So the key/keyref is actually more like PK/FK. PK only have to be unique within one table.