logo       

Related Msgs: audio.musicbrai...    enbd.general/20...    ietf.idr/2002-0...    java.ant-contri...    gnu.make.genera...    qplus.devel/200...    video.freevo.cv...    os.netbsd.ports...    yellowdog.gener...    xfree86.cvs/200...    search.nutch.us...    freedesktop.xse...    programming.swi...    capabilities.ge...    telephony.pbx.a...    mail.sylpheed.c...    db.firebase.por...    boot-loaders.u-...    recreation.radi...    netbsd.bugs/200...    web.zope.plone....    user-groups.lin...   

Re: Writing namespace information: msg#00059

Subject: Re: Writing namespace information
Here's on example (compiled against JDK 1.6) of how you would create
that element as the root element via the DOM APIs. Essentially, it
boils down to use the 'createXXXNS' and 'setXXXNS' methods.

-Nathan

import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class DOMWithNS {

        public static void main(String[] args) throws Exception {
                DocumentBuilderFactory factory = 
DocumentBuilderFactory.newInstance();
                factory.setNamespaceAware(true);
                DocumentBuilder builder = factory.newDocumentBuilder();

                // Create the Document
                Document doc = builder.newDocument();
                // Create the root element with a namespace
                Element pid = doc.createElementNS("urn:hl7-org:v2xml", 
"hl7:PID");
                // add the root element to the Document
                doc.appendChild(pid);
                // add the xmlns:hl7 attribute to this element
                pid.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, 
"xmlns:hl7",
                                "urn:hl7-org:v2xml");
                // add the xmlns:xsi attribute to this element
                pid.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, 
"xmlns:xsi",
                                XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
                // add the xsi:schemaLocation attribute
                pid.setAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI,
                                "xsi:schemaLocation", "urn:hl7-org:v2xml 
segments_test.xsd");

                // identity transform to print document to standard out
                TransformerFactory.newInstance().newTransformer().transform(
                                new DOMSource(doc), new 
StreamResult(System.out));
        }

}



On 8/31/07, fabiodap@xxxxxx <fabiodap@xxxxxx> wrote:
> Hello all,
>
> Is there a way I could specify that my document comes from
> multiple
> namespaces. There seems to be only one namespace parameter.
>
> To be clear, i want to write the following thing:
>
> <hl7:PID xsi:
> schemaLocation="urn:hl7-org:v2xml segments_test.xsd" xmlns:xsi="http:
> //www.w3.org/2001/XMLSchema-instance" xmlns:hl7="urn:hl7-org:v2xml">
>
> This is the piece of code where i create and fill the Document:
>
>
> public Document encodeDocument(Message source) throws HL7Exception {
>         String messageClassName = source.getClass().getName();
>
> String messageName = messageClassName.substring(messageClassName.
> lastIndexOf('.') + 1);
>         org.w3c.dom.Document doc = null;
>
> try {
>                 DocumentBuilderFactory dbf = DocumentBuilderFactory.
> newInstance();
>                 dbf.setNamespaceAware(true);
>                 dbf.
> setAttribute(JAXPConstants.JAXP_SCHEMA_SOURCE, "urn:hl7-org:v2xml
> segments_test.xsd");
>             doc = dbf.newDocumentBuilder().
> newDocument();
>             Element root = doc.createElement
> (messageName);
>             doc.appendChild(root);
>         }
>
> How to
> specify here the information regarding the namespaces?
>
> Greetz,
> Fabio
> Daprile
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xxxxxxxxxxxxxxxxx
> For additional commands, e-mail: j-users-help@xxxxxxxxxxxxxxxxx
>
>



Try Searching:
servers, voip, java, networking, microsoft ...
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo