Wednesday, November 26, 2008

Normalize Space....

I'm working on a project that imports data from EPIServer to SharePoint. The solution simply reads a XML file and creates publishing pages, and uploads images based on the content.

The XML structure, and data are provided by a 3rd party vendor, so I don't have control over the content.

The import seemed to work and all the images were uploaded to SharePoint. But when the users began to insert images with formatting attributes in the img tag some spaces were added to the XML source. A quick look at the XML data in Internet Explorer did not reveal anything (Do not look at XML data in IE if you are debugging, Notepad or Notepad ++ is a much better choice).

I tried to make changes to the way XMLReader reads the document, but culd not manage to make the existing XPath query work.

To solve the problem without altering the export routine I had to make a XPath Query that included the entities with, and without the extra spaces.

Here is the XML with the space in the id attribute



The XPath query that were used in previous versions did not match the id when the space were present. A solution culd have been to just add a space in the query, but that did not seem to provide a good solution...



After searching for XML and Whitespace i found the Normalize-Space function. Problem solved!

This XPath query will return the results with or without a space

No comments: