In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the example analysis created in XML, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.
Create a XML file with an associated xml schema
1. Create a new Windows application project
First, you need to create a new Windows application in Visual Basic or Visual C #. Create a new project and name it XMLCustomerList, point to New from the File menu, and then click Project to display the New Project dialog box. Depending on the language you want to use, select Visual Basic Project or Visual C# Project in the Project Type pane, and then select Windows Application. Name the project XMLCustomerList, and then click OK to create the project.
2. Visual Studio adds the XMLCustomerList project to solution Explorer.
To add a new XML file item to the project, choose add New item from the Project menu. The add New item dialog box appears. Select XML File from the templates area of the add New item dialog box. Name the XML file CustomerList, and then click Open.
3. Add a new XML schema item to the project
To add a new XML schema item to the project, choose add New item from the Project menu. The add New item dialog box appears. Select XML Schema from the templates area of the add New item dialog box. Name the schema CustomerListSchema, and then click Open.
4. Add a simple type definition to the schema
Create a simple type element that represents a 5-digit postal code
From the XML Schema tab of the Toolbox, drag a simpleType onto the design surface. Select the default name "simpleType1" and rename the type to "postalCode". Use the TAB key to navigate to the next cell on the right and select positiveInteger from the drop-down list. Use TAB to navigate to the next line.
Click the drop-down box. The only option is facet. This is because a simple type cannot contain elements or attributes as part of its content model. Only facet can be used to generate simple types. Use the TAB key to navigate to the next cell on the right and select pattern from the drop-down list. Use the TAB key again to navigate to the next cell on the right and type "\ d {5}".
The pattern facet allows you to enter regular expressions. The regular expression\ d {5} means that the content of the zip code (postalCode) type is limited to 5 digits. Regular expressions are beyond the scope of this walkthrough, but you can see how to use schema facet with the selected data type to allow only specific data in simple types.
If you switch the schema to the XML view, you should see the following code in the root-level schema tag (which means that the code example does not include the actual declaration portion of the framework, nor the actual schema tag called the root or document-level tag):
Choose Save all from the File menu.
5. Add complex type definitions to the schema
Create a complex type element that represents a standard American address
Switch to Schema view. From the XML Schema tab of the Toolbox, drag a complexType onto the design surface. Select the default name "complexType1" and rename the type to "usAddress". Do not select a data type for this element. Use TAB to navigate to the next line. Click the drop-down list box to see multiple element options that can be added to a complex type. You can select an element, but for the rest of this walkthrough, you will just skip the cell with the TAB key, because the element is the default. Use the TAB key to navigate to the next cell on the right and type "Name".
Use the TAB key to navigate to the next cell on the right and set the data type to string. Repeat to create a new line in the usAddress element for the following items:
Element name
Data type
Street string City string State string Zip postalCode
Note the data type assigned to the Postal Code (Zip) element. It is the postalCode simple type that you created previously.
If you switch to the XML view, you should see the following code in the root-level schema tag (which means that the code example does not include the actual declaration portion of the schema, nor the actual schema tag called the root or document-level tag):
Now you have defined two separate types, which can be used for element definitions as well as types. Choose Save all from the File menu. Add the main element to the schema
6. After defining some data types, you can construct the actual data definition for the XML file to be created. The XML file will contain the data for the customer list, so create the actual elements that define the data that will be valid in the XML file.
Create a Customer element
Switch to Schema view. From the XML Schema tab of the Toolbox, drag an element onto the design surface. Select the default name "element1" and rename it to "customer". Do not select a data type for this element. Use the TAB key to navigate to the center cell of the next row and type "CompanyName". Use the TAB key to navigate to the next cell on the right and set the data type to string. Repeat to create a new line in the Customer element for the following items:
Element name
Data type
ContactName string Email string Phone string BillToAddress usAddress ShipToAddress usAddress
Note the data types assigned to the Billing address (BillToAddress) element and the Shipping address (ShipToAddress) element. It is a previously created usAddress complex type. We may have defined simple types for "Email", "Phone" elements, and so on.
If you switch the schema to the XML view, you should see the following code in the root-level schema tag (which means that the code example does not include the actual declaration portion of the framework, nor the actual schema tag called the root or document-level tag):
Choose Save all from the File menu.
7. To allow multiple instances of customer data within the XML document, we will create an element called customerList, which will contain all individual customer elements.
Create a customerList element and drag a "element" from the XML Schema tab of the Toolbox onto the design surface. Select the default name "element1" and rename it to "customerList". Do not select a data type for this element. Select the customer element (previously created) and drag it onto the customerList element. A separate design pane is bound to represent the hierarchical structure of the data. Choose Save all from the File menu.
8. Associate the schema with the XML file
Create an association between the XML file and the XML schema in solution Explorer, double-click the CustomerList.xml file. The XML file opens in the designer's XML view. In the Properties window, click the cell to the right of the targetSchema property and select http://tempuri.org/CustomerListSchema.xsd".
Visual Studio adds a reference to the schema and tags in the CustomerList.xml file.
Add data to the XML file
9. You can now add data to the XML file. By associating the schema with the XML file, the XML editor now knows the valid elements that can be included in the XML file and provides a formatted grid in the data View.
Add data to the customerList.xml file, and in the "customerList.xml" file in the XML view, position the cursor between the opening and closing tags (start tag =, end tag =).
Type to end the tag.
Type to end the tag.
Type Blue Yonder Airlines as the company name.
Switch to data view. Type Nate Sun in the contact name field in the grid. Fill in the record by adding data to other fields in the grid. Switch back to XML view. The data in the grid is now properly formatted as XML.
Second, create XML schemas from XML files
Create a new XML schema based on existing XML documents
1. Load an XML document (.xml file) into the XML designer.
2. Click create Schema from the XML menu.
3. A XML schema (.xsd file) will be added to the current project with the same name as the original XML file.
4. Load the newly created XML schema (. Xsd file) into the XML designer
5. Validate and edit the data type assigned when the schema is created.
Note that when deriving schemas from existing XML documents, all data types are initially set to string, so you must edit the data types according to the content requirements of the XML data.
If you need to make changes to the schema, you can use the XML designer to add, edit, and remove elements.
Thank you for reading this article carefully. I hope the article "sample Analysis created in XML" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.