Directly Change An Xml File From One Dtd Into Another
- Directly Change An Xml File From One Dtd Into Another Form
- Directly Change An Xml File From One Dtd Into Another Computer
- Directly Change An Xml File From One Dtd Into Another Time
- How To Create An Xml File From Excel
- How To Create An Xml File From A Text File
- Mechanism Used To Directly Change An Xml File From One Dtd Into Another
2.4 XML Import
XML Data Processing Using Talend Open Studio. Posted in HOWTO, Programming, Talend on December 28, 2013. Following is a sample XML entry for one title/movie. Databases and also write to different file formats or directly insert into databases. This was just a quick introduction (tip of the iceberg) to experience the usefulness of. How to transform XML for one XSD into another XML format that is very similar but has a different XSD file? The XSD is quite large and has many complex types, but the actual XML looks very similar. I have two XSD files and two XML files - they both validate successfuly to one of the XSD files. In my example you have to xml documents the and only thing you need to know is where you want to insert the second xml file. You can easily change it and insert the second file inside the root tag of the first one etc. Transform From One XML Structure to Another. (Not a complete project, but a program file and the XML files) Introduction. XML structures are very common and sometimes it is necessary to transform from one XML structure into another. Jan 09, 2003 Hi, I am getting an XML file from an outside system and i want to convert the same file into another XML using a DTD, can anybody give me a pointer for the same. Thanks and Regards Amit. But one thing i am not clear about is. The DTD just specifies rules that an XML file must follow. It doesn't have anything to do with transforming.
FileMaker Pro can export with both the FMPXMLRESULT and FMPDSORESULT grammars. Only the FMPXMLRESULT grammar may be used for import. If you export from FileMaker Pro with FMPXMLRESULT, you may import the data directly into another FileMaker Pro database. The import steps and dialogs are similar in XML as with the other text imports. For the import setup below, make a sample FMPXMLRESULT export from any of your databases and use the file for import back into the same file.
2.41 Setting Up for XML Import
Choose File, Import Records. The contextual menu will show four options: File, Folder, XML Source, and ODBC Source. If you select File, you may navigate to an XML file and import, but FileMaker Pro will make a 'best guess' as to the file type. Even if you have the '.xml' extension on the file name, the file may be imported as tab-separated text. The exported XML file is not delimited for this kind of import. You must still specify the type of file. When you choose XML Source, you will be presented with the Specify XML and XSL Options dialog. Figure 2.6 shows this to be different from the export XML dialog as seen earlier in Figure 2.1.
You may import any XML document found on your local disks or any mounted drives on your network. As long as you can see the file on the network, you may choose it for import. The second option to import XML is to specify an HTTP request. You can select any XML file that is available through the Internet, provided you have permission to get the file. HTTP requests for FileMaker Pro web publishing are discussed in Chapter 5. If you don't know how to make an HTTP request, you may find the information in Chapter 5 useful. Usually, if you have permission to get a file, you will be given the URI to enter into the dialog. For now, ignore the stylesheet selection.
Choose File and you will be given the Open File dialog to navigate to your XML file. After you select the file, click the OK button. Remember that only XML using the FMPXMLRESULT grammar will import correctly into FileMaker Pro. If you have the correct grammar for your XML document, you will be presented with the familiar Import Field Mapping dialog as seen in Figure 2.7.
Figure 2.7: Import Field Mapping dialog
You may view the fields by 'matching names' or any of the other options. If the XML file has the names of the fields the same as the importing database, the fields will match by name. You may move the fields around and select or deselect the mapping for the fields. As with other FileMaker Pro imports, you may add new records, replace the data in the current found set, or update matching records in the current found set. Click the Import button to bring the data in from the XML document. You can read more about the import options in section 11 of the FileMaker Pro Help topic 'Importing data into an existing file.' If your field names do not match and you want to import your XML easily, the examples in Exercise 2.5 will show you different ways to do this.
2.42 FMPXMLRESULT Import
The FMPXMLRESULT grammar is the only method of importing XML data into FileMaker Pro. The correct structure of the XML document for importing into FileMaker Pro 6 is necessary. You will get errors when you try to import XML that does not comply with the FMPXMLRESULT grammar. The error dialogs may give you a clue to what is wrong when you import XML. Export a small set of records from any database that you may be using for XML import. Select FMPXMLRESULT and study the structure of the saved XML document. Chapter 4 has more detail about this XML document structure. For many XML documents the structure rules are called Document Type Definitions. Chapter 3 discusses general DTD terms.
Directly Change An Xml File From One Dtd Into Another Form
Here are a few warnings about importing XML into specific field types in FileMaker Pro: Repeating fields do not import correctly into FileMaker Pro 6 at this time. Only the first repeat will be imported. Related field data should be imported directly into the related child file rather than the parent file. Related fields are not available in the Import Records dialog, so you cannot make any matches for import. Container fields do not import (or export) when using XML. Global fields import once, and calculation or summary fields may be imported into noncalculated fields. Date and time data may import as text and be incorrectly formatted, such as two-digit years instead of four-digit years.
Exercise 2.5: Manual Transformations with FileMaker Pro
The following are XML import examples. The first one will show you how to change the field names for import. The second example uses the same principle and shows you how to create an XSL stylesheet with the changed field names for use with Export or Import. The third example uses a FileMaker Pro database to help you create the stylesheet.
Example 1: Export, Edit the FIELD Elements, and Import
By simply editing the NAME attributes of the FIELD elements, you may be able to import the FMPXMLRESULT format directly into a new option. The field names FirstName and LastName in the new file do not match, as shown in Figure 2.8. If you have used your own databases, import into your second file with the changed field names. You may find the correct fields and move them to match and then import. This task isn't so difficult with just a few fields but can be complex with many fields! Continue the import or select Cancel.
Open the XML file again in a text editor. Very carefully find the NAME attributes of the FIELD elements. The NAME='First Name' can be edited to be NAME='FirstName', for example. Change any other field names, whether you use your own databases or the examples, and save the XML document without changing anything else. Try the import again and select matching names. If you get any errors when you import, try the export again and carefully change the field names in the resulting XML document.
Example 2: Transform with a Simple Stylesheet
Directly Change An Xml File From One Dtd Into Another Computer
Changing the field names each time you want to export XML and import into a new database with different names can be time consuming if you need to perform the task multiple times. A simple XSL stylesheet can be created and used with the export or the import. The transformation takes place when you export, and the new XML will import directly. Or you can export to a file and use the XSL stylesheet with the import. As with Example 1, make a manual export and create a script to save the export options, especially the fields order. If you export only a record or two, the XML document should open easily in an XML or text editor.
Create the following XSL document in a text editor and save it as NameChange.xsl.
In the above stylesheet you will need to paste part of your exported XML. Open the XML in a text editor and find the root element '<FMPXMLRESULT>' and the end element '</METADATA>.' Copy these two elements and everything in between. Paste into the style-sheet instead of the '<!– REPLACE THIS AREA –>' line. Change the NAME attribute values for every FIELD element that will be different in your new database. Save the XSL document like the example in Listing 2.12.
Perform the export in the old file again and this time specify the stylesheet in the dialog, as seen in Figure 2.9. You may save the export in a script step and it might be similar to this:
The exported XML has been changed (transformed) by the XSL stylesheet. If you look at ExportTransformed.xml in a text editor, you may see what appears in Listing 2.13. The field names are correct for matching names in the new file, and the data has been directly copied from the old file.
Import the new XML file ExportTransformed.xml into the database Import.FP5. Do not specify the stylesheet because the data has already been changed with the export. Select matching names and all of your names should match.
You can also use the stylesheet with an import. First export your records with FMPXMLRESULT, but use the script you created so that the field order is the same as in the XSL above. Do not use the style-sheet for export. Open the Import.FP5 file and select File, Import Records, XML Source. This time select the same stylesheet, Name-Change.xsl. The XML parser and the XSLT processor in FileMaker Pro 6 will transform the XML as it is imported.
Example 3: Create a Stylesheet with FileMaker Pro
Doug Rowe, of Robyte Consulting in Jacksonville, Florida, has taken this transformation concept another step. Using the FileMaker Pro Design functions, he reads the field names into a FileMaker Pro file. His demo file will change the names and save the XSL stylesheet using the Troi-File plug-in. You can use the example XSL_Import.fp5 to read in your field names and manually change the names. Remember that the order of the fields in the export from the old database must be the same as the order of the fields in the created XSL.
2.43 Scripted XML Import
Just like the XML export, you can script the import of XML data. Take a look at the import dialog in Figure 2.11. Compare this to Figure 2.6. The scripted XML import contains one more option that is not available with the manual XML import. With the scripted import, you can specify a field to contain the path to a file for import or the path for an HTTP request to import.
Directly Change An Xml File From One Dtd Into Another Time
If the file or HTTP request returns the FMPXMLRESULT grammar, you can import directly and use the Import Field Mapping dialog, as seen in Figure 2.7. If the file or HTTP request is not the FMPXMLRESULT grammar, you can specify an XSL stylesheet by file, HTTP request, or a field with the file path or HTTP request.
The import script ImportPlain is shown below. The options are shown in the printed script:
2.44 FileMaker Pro XML Import and Other XML Schemas
The structure of your XML documents may not match the FMPXMLRESULT grammar. An example XML document is shown here:
If you study the example in Listing 2.14, you'll see that the root element is <customers>. If you were to design FileMaker Pro databases for this information, you might create the file ORDERS.FP5. You could design the file to be 'flat' and contain the smallest piece of information (the element <item>) to be one record per item. Each record might contain these fields: customerID, customerName, invoiceID, invoiceDate, invoiceTotal, itemID, itemQty, itemDescription, itemColor, and itemPrice. You would need to retrieve the information for customerID and customerName for each invoice and for each item in each invoice. The three items ordered by customer name 'Joe Brown' would be the three records in this hypothetical flat file:
123 | Joe Brown | 987 | 11/12/1997 | 25.75 | 1 | 3 | Trucks | Blue | 5.15 |
123 | Joe Brown | 987 | 11/12/1997 | 25.75 | 2 | 2 | Trucks | Red | 5.15 |
123 | Joe Brown | 859 | 12/05/1997 | 4.00 | 3 | 1 | Cars | Blue | 4.00 |
How To Create An Xml File From Excel
A flat database file such as the example above may be sufficient for a small set of data. But you can see that data is duplicated unnecessarily. The XML document shows the data in the tree structure. Only the necessary information is available. By design, the child elements inherit the parent's information. Even though the document is 'flat', it really contains relational data. The next example places the related XML information where needed.
You could create three related files: CUSTOMERS.FP5, INVOICES.FP5, and ITEMS.FP5. The relationship match field customerID would be in all three files. The relationship match field invoiceID would be in the INVOICES and ITEMS files. Table 2.3 shows the databases and the fields in each file:
CUSTOMERS | customerID, customerName |
INVOICES | customerID, invoiceID, invoiceDate, invoiceTotal |
ITEMS | customerID, invoiceID, itemID, itemQty, itemDescription, itemColor, itemPrice |
The XSL stylesheets for importing the XML shown in Listing 2.14 into FileMaker Pro 6 will be presented in Chapter 7. For now, these examples illustrate the XML that you may encounter and thoughts on designing the databases for importing XML from other sources. Study the structure of XML documents and find the patterns of data. Some data may be in elements and some data may be in attributes, such as customerID, invoiceID, and itemID. Elements that repeat within an XML document may be good candidates for separate databases and individual records.
How To Create An Xml File From A Text File
-->The ImportNode method is the mechanism by which a node or entire node subtree is copied from one XmlDocument to another. The node returned from the call is a copy of the node from the source document, including attribute values, the node name, node type, and all namespace-related attributes such as the prefix, local name, and namespace Uniform Resource Identifier (URI). The source document is not changed. After you have imported the node, you still have to add it to the tree using one of the methods used to insert nodes.
When the node is attached to its new document, the new document owns the node. The reason is that each node, when created, has an owning document, even if the nodes are created in separate document fragments. This is a requirement of the XML Document Object Model (DOM) and is enforced by the factory creation design on the XmlDocument class. For example, CreateElement, is the only way to create new nodes.
Depending on the node type of the imported node and the value of the deep parameter, additional information is copied as appropriate. This method attempts to mirror the behavior expected if a fragment of XML or HTML source was copied from one document to another, accounting for the fact that for XML, the two documents may have different document type definitions (DTDs).
The following table describes the specific behavior for each type of node that can be imported.
Node Type | deep parameter is true | deep parameter is false |
---|---|---|
XmlAttribute | The Specified is set to true on the XmlAttribute. The descendants of the source XmlAttribute are recursively imported and the resulting nodes reassembled to form the corresponding subtree. | The deep parameter does not apply to XmlAttribute nodes, because they always carry their child nodes with them when imported. |
XmlCDataSection | Copies the node, including its data. | Copies the node, including its data. |
XmlComment | Copies the node, including its data. | Copies the node, including its data. |
XmlDocumentFragment | The descendants of the source node are recursively imported and the resulting nodes reassembled to form the corresponding subtree. | An empty XmlDocumentFragment is created. |
XmlDocumentType | Copies the node, including its data.* | Copies the node, including its data.* |
XmlElement | The descendants of the source element are recursively imported and the resulting nodes reassembled to form the corresponding subtree. Note: Default attributes are not copied. If the document being imported into defines default attributes for this element name, those are assigned. | Specified attribute nodes of the source element are imported, and the generated XmlAttribute nodes are attached to the new element. The descendant nodes are not copied. Note: Default attributes are not copied. If the document being imported into defines default attributes for this element name, those are assigned. |
XmlEntityReference | Because the source and destination documents could have the entities defined differently, this method only copies the XmlEntityReference node. The replacement text is not included. If the destination document has the entity defined, its value is assigned. | Because the source and destination documents could have the entities defined differently, this method only copies the XmlEntityReference node. The replacement text is not included. If the destination document has the entity defined, its value is assigned. |
XmlProcessingInstruction | Copies the target and data value from the imported node. | Copies the target and data value from the imported node. |
XmlText | Copies the node, including its data. | Copies the node, including its data. |
XmlSignificantWhitespace | Copies the node, including its data. | Copies the node, including its data. |
XmlWhitespace | Copies the node, including its data. | Copies the node, including its data. |
XmlDeclaration | Copies the target and data value from the imported node. | Copies the target and data value from the imported node. |
All other node types | These node types cannot be imported. | These node types cannot be imported. |
Note
Although DocumentType nodes can be imported, a document can only have one DocumentType. So, once you have imported the document type, before inserting it into tree you have to make sure that there is no document type in the document. For information on removing nodes, see Removing Nodes, Content, and Values from an XML Document.