« Return to Thread: How to create a document with the xsd as a document type

Re: How to create a document with the xsd as a document type

by polx :: Rate this Message:

Reply to Author | View in Thread

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>
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@...

 « Return to Thread: How to create a document with the xsd as a document type