Question

Editing XML File


Badge
Hello everyone,

 

 

I want to make changes to existing XML files based on Microsoft Word in FME Desktop 2015, for that I use the XMLReader (Elements to Match: *; Flattening enabled and using the workflow Option Single Merged FT) and the XMLWriter.

 

All I did by now is connecting the reader and the writer to get an exact copy of the XML file, but it creates an XML File including tags (<fme:*>) that I don't want to be in there.

 

For example: 
 <fme:xml-tables xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:fme="http://www.safe.com/xml/xmltables" xsi:schemaLocation="http://www.safe.com/xml/xmltables FME_EDDH2_Testfile.xsd"> 	<fme:family-table> 		<fme:family> 			<Relationship xmlns="http://schemas.openxmlformats.org/package/2006/relationships" Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/> 			<fme:xml_id>id-Relationship-1.1.1.1.1</fme:xml_id> 			<fme:xml_matched_element>Relationship</fme:xml_matched_element> 			<fme:xml_parent_child_pos>0</fme:xml_parent_child_pos> 			<fme:xml_parent_id>id-Relationships-1.1.1.1</fme:xml_parent_id> 			<fme:Relationship.Type>http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties</fme:Relationship.Type> 			<fme:Relationship/> 			<fme:Relationship.Id>rId3</fme:Relationship.Id> 			<fme:Relationship.Target>docProps/app.xml</fme:Relationship.Target> 			<fme:Relationships.xmlns>http://schemas.openxmlformats.org/package/2006/relationships</fme:Relationships.xmlns> 		</fme:family> 	</fme:family-table> </fme:xml-tables>
 Is it possible to create such a copy with the XML Reader/Writer? Am I missing a setting?

 

I also noticed that the declaration 
 <?mso-application progid="Word.Document"?>
 was missing in the created XML file and I can't find it in the User Attributes.

 

 

Any help is appreciated

 

 

Melanie

3 replies

Userlevel 2
Badge +17
Hi Melanie,

 

 

You can control the target namespace and its prefix through these parameters of the XML writer.

 

Target Namespace URI

 

Target Namespace Prefix

 

 

To omit the namespace prefix, specify a URI to the "Target Namespace URI" explicitly and leave the "Target Namespace Prefix" blank. e.g.

 

Target Namespace URI: http://www.my_domain.com/my_schema

 

Target Namespace Prefix: <not set>

 

 

Regarding the missing "<?mso-application progid="Word.Document"?>".

 

It's not a standard XML element, maybe is a Microsoft specification.

 

I don't think that the XML reader can read it, because it's not a part of the XML document.

 

 

Takashi
Userlevel 4
Hi,

 

 

the "<?mso-application progid="Word.Document"?>" part is an XML processing instruction (http://en.wikipedia.org/wiki/Processing_Instruction).

 

 

The easiest solution is probably to just concatenate that bit (as a constant) onto the XML string just before sending it to the writer.

 

 

David
Badge
Hi,

 

Thanks for your help.

 

Using the XMLReader and XMLWriter causes some Problems in my case so i decided to use the Text File Reader and Writer.

 

I also tried the XMLUpdate Transformer, but somehow it doesn't change anything. For testing I used Update Type: delete and XML Path: /pkg:package/pkg:part[0] but nothing happens. The XML I want to update: 
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <!--<?mso-application progid="Word.Document"?>--> <pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage">     <pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml" pkg:padding="512">          ....
 

 

I noticed an error in my Log 
 XMLWordTableUpdater_2_XMLUpdater(XQueryFactory2): The following error occurred while executing query number 1: XMLWordTableUpdater_2_XMLUpdater(XQueryFactory2): The following error occurred near line 2, column 8 of the query: XMLWordTableUpdater_2_XMLUpdater(XQueryFactory2): target expression is empty sequence
 If I use /pkg:package/pkg:part[1] for XML Path i don't get an error, but it still doesn't do anything. Does it start to count at 1 here?

 

Do you know what is causing this problem? What should I use for XML Path?

 

 

Best regards, Melanie

 

 

 

 

Reply