Opened 16 years ago

Closed 2 years ago

#979 closed defect (fixed)

WebLayout XML must be formatted/indented correctly whereas others (Layer, MapDefinition, Data) do not.

Reported by: cagray Owned by: jng
Priority: low Milestone: 4.0
Component: AJAX Viewer Version: 2.2.0
Severity: trivial Keywords:
Cc: External ID:

Description

When creating new resources from a xml string or file using the Web API the formatting (newlines/indenting) of the XML does not matter for Data, Layer or MapDefinition resources. However for WebLayout resources it does. If incorrectly formatted you get:

Argument is null. Argument is null

when you try and view it in the AJAX viewer through a web page (not in Maestro which works). If you save this resource in Maestro it fixes it as it formats the XML.

I would have thought that the XML in Mapguide should not rely upon the indenting etc?

I resolved this in my .NET application by running the function on the xml string:

public static String FormatXMLString(string sUnformattedXML)
{
	XmlDocument xd = new XmlDocument();
	xd.LoadXml(sUnformattedXML); 
	StringBuilder sb = new StringBuilder();
	StringWriter sw = new StringWriter(sb);
	XmlTextWriter xtw = null;
	try 
        {
		xtw = new XmlTextWriter(sw);
		xtw.Formatting = Formatting.Indented;
		xd.WriteTo(xtw);
	}
	finally {
		if (xtw != null)
			xtw.Close();
		}
	return sb.ToString();
}

and setting PreserveWhiteSpace = true on the XMLDocument object which reads the XML String/File in before encoding it to UTF8 bytes and submitting to MapGuide using SetResource.

NOTE: My xml does not have a BOM so it is not a UTF-8 encoding issue as far as I am aware.

Change History (9)

comment:1 by ksgeograf, 16 years ago

I have seen that Studio chokes with a similar error, which is why Maestro indents the xml.

I have the impression that Studio uses some of the same MapGuide dll's (MdfParser?), which could explain why this issue is also present in the MapGuide code.

comment:2 by zspitzer, 13 years ago

Milestone: 2.3
Version: 2.1.02.2.0

comment:3 by zspitzer, 13 years ago

Argument is null.

comment:4 by jng, 12 years ago

Milestone: 2.32.4

comment:5 by jng, 12 years ago

Milestone: 2.42.5

comment:6 by jng, 12 years ago

Milestone: 2.52.6

comment:7 by jng, 7 years ago

Milestone: 3.03.3

Ticket retargeted after milestone closed

comment:8 by jng, 5 years ago

Milestone: 3.34.0

Milestone renamed

comment:9 by jng, 2 years ago

Owner: set to jng
Resolution: fixed
Status: newclosed

In 10008:

Fix a 14 year old (!!!) long standing bug with MgWebLayout loading unformatted WebLayout XML. The issue is due to an unnecessary null pointer check in MgWebLayout::ParsePrintCommand(). When the XML is unformatted, the DOMNode ptr will be null, when the XML is formatted, the DOMNode ptr is not null, but inspecting this pointer shows that the DOMNode pointer is for a #text region (ie. Whitespace).

Since the method itself is ultimately trying to parse an *optional* <PrintLayout> that may or may not be present, there is no need for the incoming DOMNode ptr to actually not be null. If it's null, just bail out early and move on.

A new WebTestRunner test case has been added to exercise this particular case.

Fixes #979

Note: See TracTickets for help on using tickets.