[jdom-interest] How to create a document with the xsd as a
document type
Paul Libbrecht
paul at activemath.org
Fri Feb 23 01:03:16 PST 2007
Abelkin,
the way you sent your document actually put the XML source within HTML
not as text... not really readable thingie! (but looking at the HTML
source made it possible).
How about the following:
Namespace xsiNS =
Namespace.getNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
Element root = new Element("MyProfile");
root.setAttribute("noNamespaceSchemaLocation","file://C:/XMLSchemas/Profile/MyProfile.xsd",xsiNS);
Element ta = new Element("TA");
ta.addContent(new Text("\n\n"));
root.addContent(ta);
Document doc = new Document(root);
or the same in one (long) line:
new Document(new
Element("MyProfile").setAttribute("noNamespaceSchemaLocation","file://C:/XMLSchemas/Profile/MyProfile.xsd",Namespace.getNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance")).addContent(new
Element("TA").addContent(new Text("\n\n))));
note, oh note, that you do nothing with the doctype here... Doctype
handles with DTD, you add here namespaces and attributes.
Hope it helps.
paul
abelkin wrote:
> I need to create a XML document with the schema in the document type.
> I need to get something line this after outputting to the string:
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <MyProfile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\XMLSchemas\Profile\MyProfile.xsd">
> <TA>
>
> </TA>
> </MyProfile>
More information about the jdom-interest
mailing list