# Sitemap Validator (`eichan/sitemap-validator`) Actor

- **URL**: https://apify.com/eichan/sitemap-validator.md
- **Developed by:** [Eichan Jolly](https://apify.com/eichan) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.01 / actor start

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Sitemap Validator

Check a single public XML sitemap and get **one predictable summary dataset item**. Designed for SEO practitioners, site administrators, web developers and technical auditors who want a quick sitemap health check without logging in.

### What it checks

- Makes one HTTPS/HTTP GET request to the supplied sitemap URL (no redirect following).
- Checks HTTP status, well-formed XML, and `<urlset>` or `<sitemapindex>` format.
- For a URL sitemap, counts `<url>` entries, **capped at 10,000**, and flags missing/invalid `<loc>` values. `urlCount` is **0 for a sitemap index**: this tool does not sum the URLs in its children.
- For a sitemap index, checks **up to 20 child sitemap URLs**, including HTTP status, XML, supported root format and `<loc>` presence. Only children on the **same scheme, hostname and standard port** as the parent are fetched. Out-of-origin child URLs are reported but not requested.
- Emits a single item with readable issues instead of aborting on a malformed or unreachable sitemap.

### Example input

```json
{"sitemapUrl":"https://search.gov/sitemap.xml"}
```

The prefill is an actual public sitemap URL referenced in Search.gov's documentation. Website availability may change. No example.com placeholders are needed.

### Example output

Illustrative output (not an assertion about the current live Search.gov sitemap):

```json
{
  "sitemapUrl": "https://search.gov/sitemap.xml",
  "httpStatus": 200,
  "isValidXml": true,
  "format": "urlset",
  "urlCount": 3,
  "childSitemaps": [],
  "issues": [],
  "status": "ok",
  "error": null
}
```

For sitemap indices, `format` is `index`, `urlCount` is `0`, and `childSitemaps` contains up to 20 objects with `url`, `httpStatus` (integer or null) and `valid` (boolean). `format` is `invalid` for unsupported XML. `status` is `ok`, `issues`, or `error`. A missing `<loc>` yields `status: "issues"`; malformed XML yields `status: "error"` and `error` containing a plain-language message.

### Honest limitations

- **Not an exhaustive crawler:** does not visit page `<loc>` URLs, verify page indexability, recursively traverse nested sitemap indices, or scan more than 20 index children.
- The 10,000 entry counting cap applies to each document inspected; additional entries are not counted. A 10 MB downloaded/uncompressed XML limit also applies.
- Only HTTP 200 responses are parsed, and HTTP redirects are not followed. Submit the final URL if a redirect occurs.
- Private / special-use IP destinations, IP-literal URLs, non-standard ports, credentials, login paths and cross-origin child requests are blocked. Public DNS resolution and TLS validation are used. Child URL links discovered in the parent XML are read only within that same origin.
- Valid XML does not guarantee an SEO-valid sitemap; the checks focus on basic XML shape and required `<loc>` values. A syntactically valid HTML document is not treated as a sitemap.
- A sitemap index may contain external children. Such children appear in `childSitemaps` with `valid: false` and a safety-related issue rather than being fetched.

### Run locally

Python 3.12+; standard library only. From this Actor folder:

```bash
ACTOR_INPUT_JSON='{"sitemapUrl":"https://search.gov/sitemap.xml"}' python src/main.py
```

Or put input JSON in `storage/key_value_stores/default/INPUT.json`. Output is written as numbered items to `storage/datasets/default/*.json`. Set `APIFY_LOCAL_STORAGE_DIR` to change the local storage root.

On Apify, the Actor **reads input from the run's default key-value store** through `GET /v2/key-value-stores/{id}/records/{inputKey}` and **appends output to its default dataset** through `POST /v2/datasets/{id}/items`. It uses the automatically provided `APIFY_TOKEN` and run storage identifiers only—buyers provide no credentials. `ACTOR_INPUT_JSON` is a testing/local override. No SDK is installed.

### Verification

```bash
python tests/run_smoke.py
python -m unittest discover -s tests -p 'test_*.py' -v
```

Smoke runner executes **`python src/main.py` as a subprocess** with valid public-URL input and a local, controlled HTTPS fixture. See `verification/script-mode-smoke.txt` and `verification/dataset-items.json`. This is not evidence of successful live website access or an Apify cloud deployment.

### Store / pricing recommendation

Category: **`DEVELOPER_TOOLS`**. Suggested: **$0.004 per successful Actor run** (pay-per-event, not per child or per dataset row); proposal only. No billing, listing, or publication configured. See `store_metadata.json`.

# Actor input Schema

## `sitemapUrl` (type: `string`):

One publicly accessible XML sitemap or sitemap-index URL; only same-origin child sitemaps are fetched.

## Actor input object example

```json
{
  "sitemapUrl": "https://search.gov/sitemap.xml"
}
```

# Actor output Schema

## `dataset` (type: `string`):

Dataset containing the Actor's result items

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "sitemapUrl": "https://www.djangoproject.com/sitemap.xml"
};

// Run the Actor and wait for it to finish
const run = await client.actor("eichan/sitemap-validator").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "sitemapUrl": "https://www.djangoproject.com/sitemap.xml" }

# Run the Actor and wait for it to finish
run = client.actor("eichan/sitemap-validator").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "sitemapUrl": "https://www.djangoproject.com/sitemap.xml"
}' |
apify call eichan/sitemap-validator --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,eichan/sitemap-validator"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/JaRv0ids9Io6xC8gX/builds/0buGZFG1TfwSmeZae/openapi.json
