The code that does the loading from a string is as follows: org.w3c.dom.Document document = null; try { DocumentBuilderFactory factory = org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.newInstance(); factory.setNamespaceAware(false); factory.setValidating(false); DocumentBuilder builder; builder = factory.newDocumentBuilder(); document = builder.parse(new InputSource(new StringReader(xml))); return document.getDocumentElement(); }
I can see in the document element that is returned that the changes have been made from the source string. Ian Lewis-3 wrote: > > Mike, > > Another thing that might be useful is to check the DOM to see if the > changes are happening after loading it, or when you are serializing it > back into XML. How are you serializing the XML? > > 07/10/04 に Ian Lewis<[EMAIL PROTECTED]> さんは書きました: >> Hmm, >> >> In most circumstances the XML should not be modified. How are you >> loading the XML? Do you have some example code where this happens? >> >> 2007/10/4, Mike Gardiner <[EMAIL PROTECTED]>: >> > Hello, >> > >> > I'm trying to load some XML without it being modified but from what I >> > see, no matter which way I load it (.setNamespaceAware = true|false) >> > java is making modifications to my XML. >> > >> > Eg: >> > >> > If I have source XML >> > >> > <root xmlns:ns="http://someURI.net"> >> > <ns:tag1>some value</ns:tag1> >> > <ns:tag2> >> > <tag3>some value for tag 3</tag3> >> > </ns:tag2> >> > </root> >> > >> > And I load it using a DocumentBuilderFactory with >> > .setNamespaceAware=true I get: >> > >> > <root xmlns:ns="http://someURI.net"> >> > <ns:tag1>some value</ns:tag1> >> > <ns:tag2> >> > <ns5:tag3 xmlns="http://test.net" xmlns:ns5="http://test.net">some >> > value for tag 3</ns5:tag3> >> > </ns:tag2> >> > </root> >> > >> > And if I load it using .setNamespaceAware=false I get: >> > >> > <root xmlns:ns="http://someURI.net"> >> > <ns:tag1 xmlns:ns="">some value</ns:tag1> >> > <ns:tag2 xmlns:ns=""> >> > <tag3>some value for tag 3</tag3> >> > </ns:tag2> >> > </root> >> > >> > >> > So basically what I'm asking is how do I load my source XML as it is >> > without having Java modify it? >> > >> > I have tags that don't have namespace information, and that is by >> > design, but if I load the XML and let java assign a random namespace >> > to it, it's no longer the same XML. And if I tell the document builder >> > to not be namespace aware then it starts redefining namespaces to "". >> > >> > --------------------------------------------------------------------- >> > To unsubscribe, e-mail: [EMAIL PROTECTED] >> > For additional commands, e-mail: [EMAIL PROTECTED] >> > >> > >> >> >> -- >> Ian Lewis >> [EMAIL PROTECTED] >> http://www.ianlewis.org/ >> http://jsxe.sourceforge.net >> > > > -- > Ian Lewis > [EMAIL PROTECTED] > http://www.ianlewis.org/ > http://jsxe.sourceforge.net > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- View this message in context: http://www.nabble.com/namespace-shenagans-tf4563703.html#a13042022 Sent from the Xerces - J - Users mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]