Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » Formatting XML StructuredDocuments (NPE while formatting a newly created element outside of an editor)
Formatting XML StructuredDocuments [message #677501] Wed, 08 June 2011 13:12 Go to previous message
Gerry Kessler is currently offline Gerry Kessler
Messages: 125
Registered: July 2009
Senior Member
I am having some difficulties formatting an xml structured document, and was looking for some advice on how to resolve it. I am using Indigo RC4.

In a nutshell, I am programatically adding a new element to a document, formatting that element, and then performing a save.

Below is a fairly close representation of the code:
	...
	IStructuredModel model= null;
	try {
		...
		model = StructuredModelManager.getModelManager().getModelForEdit(file);
		model.beginRecording(this, "Add Some Element");

		Element elem = doCreateElement();
		((IDOMModel) model).getDocument().getDocumentElement()
				.appendChild(reg);

		FormatProcessorXML formatter = new FormatProcessorXML();
		formatter.formatNode(elem);
		
		model.endRecording(this);
		...
	} finally {
		...
		model.save();
	}


The above works fine if the model is open in an xml editor. However when it is not I will usually get at an NPE in the formatter.

java.lang.NullPointerException
	at org.eclipse.wst.xml.core.internal.provisional.format.NodeFormatter.getLineDelimiter(NodeFormatter.java:215)
	at org.eclipse.wst.xml.core.internal.provisional.format.NodeFormatter.formatIndentationBeforeNode(NodeFormatter.java:161)
	...


For some reason the IStructuredDocument is null for the newly created element:

     Line 160:  IStructuredDocument doc = node.getModel().getStructuredDocument();


Am I missing a step?

Thanks,
Gerry


 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic:Cannot shut down Apache Tomcat 6.0
Next Topic:Multiple sourceElementParsers extensions per project
Goto Forum:
  


Current Time: Thu May 23 00:55:50 EDT 2013

Powered by FUDForum. Page generated in 0.01782 seconds