powered by simpleCommunicator - 2.0.56     © 2025 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Caché, Ensemble, DeepSee, MiniM, IRIS, GT.M [игнор отключен] [закрыт для гостей] / Намеренное игнорирование тегов при Correlate и Next класса %XML.Reader
4 сообщений из 4, страница 1 из 1
Намеренное игнорирование тегов при Correlate и Next класса %XML.Reader
    #39466597
drakut
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Для парсинга *.xlsx с помощью XML Schema Wizard и xml-схем были созданы необходимые классы (схемы: https://svn.cesecore.eu/svn/signserver/vendor/openxml4j/current/src/schemas/, совет от Tony на https://groups.google.com/forum/#!topic/intersystems-public-cache/xabfh8UXoeo).

Все было хорошо до попытки загрузки файла Excel 2013. В ..\xl\workbook.xml появились неопределенные пространства имен и свойства:
Код: xml
1.
2.
3.
4.
5.
<mc:AlternateContent xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
	<mc:Choice Requires="x15">
		<x15ac:absPath url="C:\Users\User\" xmlns:x15ac="http://schemas.microsoft.com/office/spreadsheetml/2010/11/ac"/>
	</mc:Choice>
</mc:AlternateContent>


И при выполнении у метода загрузки из файла:
Код: vbnet
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
Method LoadFromFile(path) As %Status 
{
	s reader = ##class(%XML.Reader).%New()
	s reader.IgnoreSAXWarnings = 1
	s reader.%DispatchGetProperty("AlternateContent") = ""
	s path = ##class(%File).NormalizeFilename(..ReportDir_..#WorkbookPath)
	s status = reader.OpenFile(path)
	q:status'=$$$OK status
	d reader.Correlate("workbook","Lib.Util.OOXML.SML.CTWorkbook")
	s res = reader.Next(.workbook,.status) 
	q:('res)&(status'=$$$OK) status
	s ..workbook = workbook
	q status
}



возникает ошибка:
ОШИБКА #6237: Неожиданный тег при XML вводе: AlternateContent (заканчивается в строке 2 символ 530)

Про AlternateContent написано на https://wiki.openoffice.org/wiki/OOXML/Markup_Compatibility_and_Extensibility - это новшества 2013 версии офиса, не входящие в стандарт OOXML, и может встречаться в любом месте, в том числе и в ..\xl\worksheets\sheet[n], что еще более усугубляет ситуацию (думал подгружать только листы).

Внимание вопрос: как проигнорировать неподдерживаемые неймспейсы и свойства?

Использование только поддерживаемых версий офиса прошу не предлагать.
...
Рейтинг: 0 / 0
Намеренное игнорирование тегов при Correlate и Next класса %XML.Reader
    #39466767
eduard93
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
drakut, AlternateContent вполне входит в стандарт , хоть и не входит в xsd.
L.1.18.4 Roundtripping Alternate Content (ECMA-376 v5 p1 pg4631)Office Open XML defines a mechanism for the storage of content which is not defined by this Office Open XML specification, for example extensions developed by future software applications which leverage the Office Open XML formats. This mechanism allows for the storage of a series of alternative representations of content, of which the consuming application can use the first alternative whose requirements are met. Consider an application which creates a new paragraph property intended to make the colors of its text change randomly when it is displayed. This functionality is not defined in this Office Open XML specification, and so the application might choose to create an alternative representation setting a different manual color on each character for clients which do not understand this extension using an AlternateContent block as follows:
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
<ve:AlternateContent xmlns:ve="…">
	<ve:Choice Requires="colors" xmlns:colors="urn:randomTextColors">
		<w:p>
			<w:pPr>
				<colors:random colors:val="true" />
			</w:pPr>
			<w:r>
				<w:t>Random colors!</w:t>
			</w:r>
		</w:p>
	</ve:Choice>
	<ve:Fallback>
		<w:p>
			<w:r>
				<w:rPr>
					<w:color w:val="FF0000" />
				</w:rPr>
				<w:t>R</w:t>
			</w:r>
			<w:r>
				<w:rPr>
					<w:color w:val="00FF00" />
				</w:rPr>
				<w:t>a</w:t>
			</w:r>
		</w:p>
	</ve:Fallback>
</ve:AlternateContent>


The Choice element that requires the new color extensions uses the random element in its namespace, and the Fallback element allows clients that do not support this namespace to see an appropriate alternative representation. These alternate content blocks can occur at any location within a WordprocessingML document, and applications must handle and process them appropriately (taking the appropriate choice). However, WordprocessingML does not explicitly define a set of locations where applications must attempt to store and roundtrip all non-taken choices whenever possible. If an application does not understand the colors extension, the resulting file (if alternate choices are to be preserved would appear as follows:Annex L

Код: xml
1.
2.
3.
4.
5.
6.
<ve:AlternateContent xmlns:ve="…">
	<ve:Choice Requires="colors" xmlns:colors="urn:randomTextColors">
	</ve:Choice>
	<ve:Fallback>
	</ve:Fallback>
</ve:AlternateContent>


The file would then appear as follows after the choice is processed:
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
<w:p>
	<w:r>
		<w:rPr>
			<w:color w:val="FF0000" />
		</w:rPr>
		<w:t>R</w:t>
	</w:r>
	<w:r>
		<w:rPr>
			<w:color w:val="00FF00" />
		</w:rPr>
		<w:t>a</w:t>
	</w:r>
</w:p>


Ваша проблема может быть решена добавлением параметров в сгенерированные XML классы:

Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
/// The XMLIGNOREINVALIDTAG parameter allows the programmer to control handling of unexpected
/// elements in the XML input.  
/// By default (XMLIGNOREINVALIDTAG = 0), will treat an unexpected element as an error.
/// If XMLIGNOREINVALIDTAG is set = 1, then unexpected elements will be ignored. 
Parameter XMLIGNOREINVALIDTAG As BOOLEAN = 1;

/// The XMLIGNOREINVALIDATTRIBUTE parameter allows the programmer to control handling of unexpected
/// attributes in the XML input.  
/// By default (XMLIGNOREINVALIDATTRIBUTE = 1), will ignore unexpected attributes.
/// If XMLIGNOREINVALIDTAG is set = 0, then an unexpected attribute will be treated as an error.
Parameter XMLIGNOREINVALIDATTRIBUTE As BOOLEAN = 1;



Могу также порекомендовать мою статью про разбор docx .
...
Рейтинг: 0 / 0
Намеренное игнорирование тегов при Correlate и Next класса %XML.Reader
    #39467082
drakut
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
eduard93,
Попробовал добавить указанные вами параметры в сгенерированный класс Lib.Util.OOXML.SML.CTWorkbook, с которым и коррелирую данные файла, но ошибка все равно почему-то возникает (та же самая), хотя по идее не должна
...
Рейтинг: 0 / 0
Намеренное игнорирование тегов при Correlate и Next класса %XML.Reader
    #39467114
drakut
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
eduard93, спасибо вам большое!
Получилось, оказывается:

Note: If XMLSEQUENCE is 1, the XMLIGNOREINVALIDTAG parameter is ignored.
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / Caché, Ensemble, DeepSee, MiniM, IRIS, GT.M [игнор отключен] [закрыт для гостей] / Намеренное игнорирование тегов при Correlate и Next класса %XML.Reader
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]