XML 示例
XML(可扩展标记语言)格式示例,从简单到复杂结构
📝 简单图书信息
🟢 simple
基本的图书 XML 结构
<?xml version="1.0" encoding="UTF-8"?>
<book>
<title>Introduction to Programming</title>
<author>John Smith</author>
<isbn>978-3-16-148410-0</isbn>
<publisher>Tech Books</publisher>
<year>2024</year>
<price currency="USD">29.99</price>
<categories>
<category>Programming</category>
<category>Technology</category>
</categories>
</book>
📝 客户数据
🟡 intermediate
包含客户信息的 XML 结构
<?xml version="1.0" encoding="UTF-8"?>
<customer id="CUST12345">
<personal>
<first_name>Jane</first_name>
<last_name>Johnson</last_name>
<birth_date>1990-05-15</birth_date>
<gender>F</gender>
</personal>
<contact>
<email>[email protected]</email>
<phone>+1-555-0123</phone>
<mobile>+1-555-0124</mobile>
</contact>
<address type="billing">
<street>123 Main St</street>
<city>New York</city>
<state>NY</state>
<zip>10001</zip>
<country>USA</country>
</address>
<address type="shipping">
<street>123 Main St</street>
<city>New York</city>
<state>NY</state>
<zip>10001</zip>
<country>USA</country>
</address>
<membership>
<level>Gold</level>
<join_date>2020-01-15</join_date>
<expiry_date>2025-12-31</expiry_date>
<discount_percentage>15</discount_percentage>
</membership>
</customer>
📝 发票信息
🟡 intermediate
商业发票的 XML 表示
<?xml version="1.0" encoding="UTF-8"?>
<invoice>
<header>
<invoice_number>INV-2024-001</invoice_number>
<invoice_date>2024-01-15</invoice_date>
<due_date>2024-02-14</due_date>
<status>Paid</status>
</header>
<seller>
<name>Tech Solutions Inc.</name>
<address>
<street>456 Business Ave</street>
<city>San Francisco</city>
<state>CA</state>
<zip>94102</zip>
<country>USA</country>
</address>
<tax_id>12-3456789</tax_id>
</seller>
<buyer>
<name>Global Enterprises LLC</name>
<address>
<street>789 Corporate Blvd</street>
<city>Los Angeles</city>
<state>CA</state>
<zip>90001</zip>
<country>USA</country>
</address>
<tax_id>98-7654321</tax_id>
</buyer>
<items>
<item id="1">
<description>Laptop Computer</description>
<quantity>2</quantity>
<unit_price currency="USD">899.99</unit_price>
<total currency="USD">1799.98</total>
</item>
<item id="2">
<description>Office Chair</description>
<quantity>4</quantity>
<unit_price currency="USD">149.99</unit_price>
<total currency="USD">599.96</total>
</item>
<item id="3">
<description>Desk Lamp</description>
<quantity>2</quantity>
<unit_price currency="USD">49.99</unit_price>
<total currency="USD">99.98</total>
</item>
</items>
<summary>
<subtotal currency="USD">2499.92</subtotal>
<tax_rate>8.5</tax_rate>
<tax_amount currency="USD">212.49</tax_amount>
<total currency="USD">2712.41</total>
</summary>
</invoice>
📝 Web 配置文件
🟡 intermediate
Web 应用程序配置
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings>
<add key="AppName" value="MyWebApplication" />
<add key="Version" value="1.0.0" />
<add key="Environment" value="Production" />
</appSettings>
<connectionStrings>
<add name="DefaultConnection"
connectionString="Server=localhost;Database=myapp;User Id=user;Password=password;"
providerName="System.Data.SqlClient" />
<add name="RedisConnection"
connectionString="localhost:6379"
providerName="Redis" />
</connectionStrings>
<system.web>
<compilation debug="false" targetFramework="4.8" />
<httpRuntime targetFramework="4.8" />
<sessionState mode="InProc" timeout="30" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
</modules>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
</staticContent>
<httpCompression>
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/atom+xml" enabled="true" />
<add mimeType="application/xaml+xml" enabled="true" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="application/atom+xml" enabled="true" />
<add mimeType="application/xaml+xml" enabled="true" />
</staticTypes>
</httpCompression>
</system.webServer>
</configuration>
📝 RSS 订阅源
🟡 intermediate
RSS feed 格式示例
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Tech News Daily</title>
<link>https://example.com</link>
<description>Latest technology news and updates</description>
<language>en-us</language>
<copyright>Copyright 2024 Tech News</copyright>
<managingEditor>[email protected] (Editor)</managingEditor>
<webMaster>[email protected] (Webmaster)</webMaster>
<pubDate>Mon, 15 Jan 2024 12:00:00 GMT</pubDate>
<lastBuildDate>Mon, 15 Jan 2024 12:00:00 GMT</lastBuildDate>
<category>Technology</category>
<generator>Tech News Generator 1.0</generator>
<docs>https://www.rssboard.org/rss-specification</docs>
<cloud domain="rpc.example.com" port="80" path="/RPC2" registerProcedure="ping" protocol="soap"/>
<ttl>60</ttl>
<item>
<title>New AI Technology Breakthrough</title>
<link>https://example.com/articles/ai-breakthrough</link>
<description>Scientists announce a major breakthrough in artificial intelligence technology that could revolutionize computing.</description>
<author>[email protected] (John Smith)</author>
<category>AI</category>
<category>Research</category>
<comments>https://example.com/articles/ai-breakthrough/comments</comments>
<enclosure url="https://example.com/audio/ai-interview.mp3" type="audio/mpeg" length="1234567"/>
<guid isPermaLink="true">https://example.com/articles/ai-breakthrough</guid>
<pubDate>Mon, 15 Jan 2024 10:30:00 GMT</pubDate>
<source url="https://source.example.com/rss">AI Research Journal</source>
</item>
<item>
<title>Cloud Computing Trends for 2024</title>
<link>https://example.com/articles/cloud-trends-2024</link>
<description>Industry experts share their predictions for cloud computing trends in 2024, including edge computing and serverless architectures.</description>
<author>[email protected] (Jane Doe)</author>
<category>Cloud Computing</category>
<category>Industry Trends</category>
<guid isPermaLink="true">https://example.com/articles/cloud-trends-2024</guid>
<pubDate>Sun, 14 Jan 2024 15:45:00 GMT</pubDate>
</item>
<item>
<title>Web Development Best Practices</title>
<link>https://example.com/articles/web-dev-best-practices</link>
<description>Comprehensive guide to modern web development best practices, including performance optimization and security measures.</description>
<author>[email protected] (Senior Developer)</author>
<category>Web Development</category>
<category>Tutorial</category>
<guid isPermaLink="true">https://example.com/articles/web-dev-best-practices</guid>
<pubDate>Sat, 13 Jan 2024 09:15:00 GMT</pubDate>
</item>
</channel>
</rss>
📝 网站地图
🟡 intermediate
搜索引擎网站地图
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"
xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
<url>
<loc>https://example.com/</loc>
<lastmod>2024-01-15T10:00:00+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://example.com/about</loc>
<lastmod>2024-01-10T15:30:00+00:00</lastmod>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://example.com/products</loc>
<lastmod>2024-01-14T12:00:00+00:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.9</priority>
<image:image>
<image:loc>https://example.com/images/products-main.jpg</image:loc>
<image:title>Our Product Line</image:title>
<image:caption>High-quality products for your business</image:caption>
</image:image>
</url>
<url>
<loc>https://example.com/blog/new-ai-technology</loc>
<lastmod>2024-01-15T10:30:00+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>0.7</priority>
<news:news>
<news:publication>
<news:name>Tech Blog</news:name>
<news:language>en</news:language>
</news:publication>
<news:publication_date>2024-01-15T10:30:00+00:00</news:publication_date>
<news:title>New AI Technology Breakthrough</news:title>
</news:news>
<image:image>
<image:loc>https://example.com/images/ai-technology.jpg</image:loc>
<image:title>AI Technology</image:title>
</image:image>
</url>
<url>
<loc>https://example.com/products/laptop-pro</loc>
<lastmod>2024-01-12T09:15:00+00:00</lastmod>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
<image:image>
<image:loc>https://example.com/images/laptop-pro-front.jpg</image:loc>
<image:title>Laptop Pro - Front View</image:title>
</image:image>
<image:image>
<image:loc>https://example.com/images/laptop-pro-side.jpg</image:loc>
<image:title>Laptop Pro - Side View</image:title>
</image:image>
</url>
<url>
<loc>https://example.com/video/product-demo</loc>
<lastmod>2024-01-11T14:20:00+00:00</lastmod>
<changefreq>monthly</changefreq>
<priority>0.6</priority>
<video:video>
<video:thumbnail_loc>https://example.com/thumbnails/product-demo.jpg</video:thumbnail_loc>
<video:title>Product Demo Video</video:title>
<video:description>See our product in action</video:description>
<video:content_loc>https://example.com/videos/product-demo.mp4</video:content_loc>
<video:duration>180</video:duration>
<video:publication_date>2024-01-11T14:20:00+00:00</video:publication_date>
</video:video>
</url>
<url>
<loc>https://example.com/contact</loc>
<lastmod>2024-01-05T11:00:00+00:00</lastmod>
<changefreq>yearly</changefreq>
<priority>0.5</priority>
</url>
</urlset>
📝 SOAP 请求
🔴 complex
Web 服务 SOAP 请求示例
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<AuthenticationHeader xmlns="http://example.com/auth">
<Username>john.doe</Username>
<Password>secure_password_123</Password>
<ApiKey>abc123def456</ApiKey>
</AuthenticationHeader>
</soap:Header>
<soap:Body>
<GetCustomerDetails xmlns="http://example.com/customers">
<customerRequest>
<CustomerId>CUST12345</CustomerId>
<includeOrders>true</includeOrders>
<includePaymentHistory>true</includePaymentHistory>
<dateRange>
<startDate>2024-01-01</startDate>
<endDate>2024-01-31</endDate>
</dateRange>
</customerRequest>
</GetCustomerDetails>
</soap:Body>
</soap:Envelope>
📝 SVG 图形
🔴 complex
可缩放矢量图形 XML
<?xml version="1.0" encoding="UTF-8"?>
<svg width="400" height="300" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Definitions for gradients and patterns -->
<defs>
<linearGradient id="skyGradient" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0%" style="stop-color:#87CEEB;stop-opacity:1" />
<stop offset="100%" style="stop-color:#E0F6FF;stop-opacity:1" />
</linearGradient>
<linearGradient id="sunGradient" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#FFD700;stop-opacity:1" />
<stop offset="100%" style="stop-color:#FFA500;stop-opacity:1" />
</linearGradient>
<pattern id="grassPattern" x="0" y="0" width="10" height="10" patternUnits="userSpaceOnUse">
<rect x="0" y="0" width="10" height="3" fill="#90EE90"/>
<rect x="0" y="3" width="10" height="7" fill="#228B22"/>
</pattern>
</defs>
<!-- Background sky -->
<rect width="400" height="200" fill="url(#skyGradient)"/>
<!-- Ground -->
<rect y="200" width="400" height="100" fill="url(#grassPattern)"/>
<!-- Sun -->
<circle cx="350" cy="50" r="30" fill="url(#sunGradient)">
<animate attributeName="r" values="30;32;30" dur="3s" repeatCount="indefinite"/>
</circle>
<!-- Clouds -->
<g opacity="0.8">
<ellipse cx="80" cy="60" rx="30" ry="20" fill="white"/>
<ellipse cx="100" cy="55" rx="35" ry="25" fill="white"/>
<ellipse cx="120" cy="60" rx="30" ry="20" fill="white"/>
<animateTransform attributeName="transform" type="translate"
values="0,0;50,0;0,0" dur="20s" repeatCount="indefinite"/>
</g>
<!-- House -->
<g>
<!-- House base -->
<rect x="150" y="140" width="100" height="80" fill="#CD853F" stroke="#8B4513" stroke-width="2"/>
<!-- Roof -->
<polygon points="140,140 200,100 260,140" fill="#8B4513" stroke="#654321" stroke-width="2"/>
<!-- Door -->
<rect x="185" y="170" width="30" height="50" fill="#654321"/>
<circle cx="210" cy="195" r="2" fill="#FFD700"/>
<!-- Windows -->
<rect x="160" y="155" width="20" height="20" fill="#87CEEB" stroke="#654321" stroke-width="2"/>
<rect x="220" y="155" width="20" height="20" fill="#87CEEB" stroke="#654321" stroke-width="2"/>
<!-- Chimney -->
<rect x="210" y="110" width="15" height="25" fill="#8B4513"/>
</g>
<!-- Tree -->
<g>
<rect x="50" y="170" width="20" height="50" fill="#8B4513"/>
<circle cx="60" cy="150" r="25" fill="#228B22"/>
<circle cx="45" cy="160" r="20" fill="#32CD32"/>
<circle cx="75" cy="160" r="20" fill="#32CD32"/>
</g>
<!-- Flowers -->
<g>
<circle cx="30" cy="210" r="5" fill="#FF69B4"/>
<circle cx="80" cy="205" r="4" fill="#FFD700"/>
<circle cx="320" cy="210" r="5" fill="#FF6347"/>
<circle cx="350" cy="205" r="4" fill="#9370DB"/>
</g>
<!-- Text label -->
<text x="200" y="290" text-anchor="middle" font-family="Arial, sans-serif"
font-size="16" fill="#333">Beautiful Day</text>
</svg>