473,396 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Associating Document with XML Schema

Hello,

I am trying to create an XML document using JAXP. I want to associate
it with a *.xsd file. How do I do that? I know if I wanted to
specify a DTD I would do something like this:

DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
factory.setValidating(true);
DocumentBuilder builder = factory.newDocumentBuilder();

// Create DTD definition
DOMImplementation domImpl = builder.getDOMImplementation();
DocumentType docType = domImpl.createDocumentType("DeviceQuery",
null, "dtd/ToolsDeviceQueryInfo.dtd");
Document toolsDoc = domImpl.createDocument(null, "DeviceQuery",
docType);

But what is the corresponding code to associate it with an .xsd file.
I have been unable to find any documentation on this.

The following is what I want the end result to look like:

<?xml version="1.0" encoding="UTF-8" ?>
<DeviceQuery
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation="DomainDeviceQueryRe sult.xsd">
<RequesterInfo>
<DQKey>12345</DQKey>
<Server>localhost:7001</Server>
</RequesterInfo>
</DeviceQuery>

Any help would be much appreciated!

Ashish
Jul 20 '05 #1
1 2045
Martin Honnen <Ma***********@t-online.de> wrote in message news:<3f********@olaf.komtel.net>...
Big Bad Munda wrote:
Hello,

I am trying to create an XML document using JAXP. I want to associate
it with a *.xsd file. How do I do that? I know if I wanted to
specify a DTD I would do something like this:

DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
factory.setValidating(true);
DocumentBuilder builder = factory.newDocumentBuilder();

// Create DTD definition
DOMImplementation domImpl = builder.getDOMImplementation();
DocumentType docType = domImpl.createDocumentType("DeviceQuery",
null, "dtd/ToolsDeviceQueryInfo.dtd");
Document toolsDoc = domImpl.createDocument(null, "DeviceQuery",
docType);

But what is the corresponding code to associate it with an .xsd file.
I have been unable to find any documentation on this.

The following is what I want the end result to look like:

<?xml version="1.0" encoding="UTF-8" ?>
<DeviceQuery
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation="DomainDeviceQueryRe sult.xsd">
<RequesterInfo>
<DQKey>12345</DQKey>
<Server>localhost:7001</Server>
</RequesterInfo>
</DeviceQuery>


Create the document and then add the attributes e.g
domDocument.getDocumentElement().setAttribute("xml ns:xsi",
"http://www.w3.org/2001/XMLSchema-instance");
domDocument.getDocumentElement.setAttributeNS(
"http://www.w3.org/2001/XMLSchema-instance",
"xsi:noNamespaceSchemaLocation",
"DomainDeviceQueryResult.xsd"
);


That was the missing piece to my puzzle. Thanks!
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jari Kujansuu | last post by:
I can successfully parse XML document using SAX or DOM and I can also validate XML document against schema. Problem is that my program should deal with user-defined schemas which means that when...
0
by: Tony Prichard | last post by:
Hi I would like to specify an XML schema that would allow an XML document to be included within another XML document. The following example schema gives an idea of what we're trying to achieve ...
3
by: marcus | last post by:
Hi All, I'm new to xml world and i was looking for a way to embed the xml schema info in the xml document itself. i tried the following: --- xml schema + document combined --- <?xml...
2
by: Stanimir Stamenkov | last post by:
I'm trying to find out if it is permissible to include a schema document with absent target namespace to a schema with specified target namespace, and if it is, what are the rules to resolve the...
0
by: Xavier Seneque | last post by:
hello, i'm trying to parse an XML file from a java program, and the structure of the XML document is described in a schema file. here is the simple schema file (departement.xsd) : <?xml...
1
by: Dave Taylor | last post by:
I'm trying to create a simple Schema and associated document in Visual Studio that will store information regarding units and conversion (meters, feet, inches, degrees C, F, K, etc.) I create a...
2
by: Marcin Cenkier | last post by:
Hi, I want to validate a DOM document, and if I build DOM from a stream using documentBuilder.parse() validation using validator.validate(DOMSource) works, but if I create the same document...
3
by: Lord0 | last post by:
I *think* I need to be able to validate subsets of an XML document using different schema. The functionality I'm trying to implement is this. a) External suppliers produce an XML document...
1
by: Mikus Sleiners | last post by:
I have a task to create xml document from c# code. I have example of that document should look like and also a xml schema. I wonder if i can use this xml schema somehow ? This is schema: ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.