### Parameters
- **prefix** (string) - Required - The prefix to use.
- **namespace** (string) - Required - The namespace URI.
### Returns
A Result containing the serializer with the prefix added, or an error.
### Example
```rust
let serializer = RdfXmlSerializer::new().with_prefix("schema", "http://schema.org/")?;
```
```
--------------------------------
### product
Source: https://docs.rs/oxrdfxml/latest/oxrdfxml/struct.RdfXmlPrefixesIter.html
Iterates over the entire iterator, multiplying all the elements.
```APIDOC
## product
### Description
Iterates over the entire iterator, multiplying all the elements.
### Method
fn product(self) -> P
### Constraints
- Self: Sized
- P: Product
### Returns
P - The product of the elements.
```
--------------------------------
### fn fold(self, init: B, f: F) -> B
Source: https://docs.rs/oxrdfxml/latest/oxrdfxml/struct.SliceRdfXmlParser.html
Folds every element into an accumulator by applying an operation, returning the final result.
```APIDOC
## fn fold(self, init: B, f: F) -> B
### Description
Folds every element into an accumulator by applying an operation, returning the final result.
### Method
`fold`
### Signature
rust
fn fold(self, init: B, f: F) -> B
where
Self: Sized,
F: FnMut(B, Self::Item) -> B,
### Parameters
- **init** (B) - Required - The initial accumulator value.
- **f** (F) - Required - A closure that takes the accumulator and an item, and returns the new accumulator.
### Returns
- **B** - The final accumulator value.
```
--------------------------------
### fn by_ref(&mut self) -> &mut Self
Source: https://docs.rs/oxrdfxml/latest/oxrdfxml/struct.SliceRdfXmlParser.html
Creates a “by reference” adapter for this instance of Iterator.
```APIDOC
## fn by_ref(&mut self) -> &mut Self
### Description
Creates a “by reference” adapter for this instance of `Iterator`.
### Method
`by_ref`
### Signature
rust
fn by_ref(&mut self) -> &mut Self
where
Self: Sized,
### Returns
- **&mut Self** - A mutable reference to the iterator.
```
--------------------------------
### RdfXmlSerializer::finish
Source: https://docs.rs/oxrdfxml/latest/oxrdfxml/struct.RdfXmlSerializer.html
Finishes serialization and returns the output.
```APIDOC
## RdfXmlSerializer::finish
### Description
Finishes serialization and returns the output as a byte slice. Returns a Result containing the output.
### Method
finish
### Signature
pub fn finish(self) -> Result, ...>
### Parameters
None
### Returns
A Result containing the serialized output as a byte vector.
### Example
```rust
let output = serializer.finish()?;
```
```
--------------------------------
### Imports for RdfXmlParser
Source: https://docs.rs/oxrdfxml/latest/src/oxrdfxml/parser.rs.html
Imports required for the RDF/XML parser implementation, including oxrdf types, quick_xml for XML parsing, and optional async support.
```rust
use crate::error::{RdfXmlParseError, RdfXmlSyntaxError};
use crate::utils::*;
use oxilangtag::LanguageTag;
use oxiri::{Iri, IriParseError};
#[cfg(feature = "rdf-12")]
use oxrdf::BaseDirection;
use oxrdf::vocab::rdf;
use oxrdf::{BlankNode, Literal, NamedNode, NamedOrBlankNode, Term, Triple};
use quick_xml::escape::{resolve_xml_entity, unescape_with};
use quick_xml::events::attributes::Attribute;
use quick_xml::events::*;
use quick_xml::name::{LocalName, Namespace, PrefixDeclaration, PrefixIter, ResolveResult};
use quick_xml::{Decoder, Error, NsReader, Writer};
use std::borrow::Cow;
use std::collections::{HashMap, HashSet};
use std::io::{BufReader, Read};
use std::str;
#[cfg(feature = "async-tokio")]
use tokio::io::{AsyncRead, BufReader as AsyncBufReader};
```
--------------------------------
### next
Source: https://docs.rs/oxrdfxml/latest/src/oxrdfxml/parser.rs.html
Asynchronously reads the next triple from the RDF/XML input. Returns None when the input is exhausted.
```APIDOC
## next
### Description
Asynchronously reads the next triple from the RDF/XML input. Returns `None` when the input is exhausted.
### Method
`pub async fn next(&mut self) -> Option>`
### Parameters
None.
### Returns
- `Option>` - `Some(Ok(triple))` if a triple is available, `Some(Err(e))` on parse error, `None` if the input is finished.
### Example
```rust
let mut parser = RdfXmlParser::new().for_tokio_async_reader(file.as_bytes());
while let Some(triple) = parser.next().await {
let triple = triple?;
// process triple
}
```
```
--------------------------------
### RdfXmlSerializer::for_tokio_async_writer
Source: https://docs.rs/oxrdfxml/latest/src/oxrdfxml/serializer.rs.html
Creates a serializer that writes RDF/XML to an asynchronous writer implementing AsyncWrite. This method is only available when the async-tokio feature is enabled.
```APIDOC
## RdfXmlSerializer::for_tokio_async_writer
### Description
Creates a serializer that writes RDF/XML to an asynchronous writer implementing AsyncWrite. This method is only available when the async-tokio feature is enabled.
### Method
for_tokio_async_writer
### Signature
pub fn for_tokio_async_writer(self, writer: W) -> TokioAsyncWriterRdfXmlSerializer
### Parameters
- **writer** (W) - Required - The asynchronous writer to write the RDF/XML output to. Must implement AsyncWrite and Unpin.
### Return Value
Returns a TokioAsyncWriterRdfXmlSerializer that can be used to serialize triples and finish the output.
### Usage Example
```rust
use oxrdf::{NamedNodeRef, TripleRef, LiteralRef};
use oxrdf::vocab::rdf;
use oxrdfxml::RdfXmlSerializer;
let mut serializer = RdfXmlSerializer::new().with_prefix("schema", "http://schema.org/")?.for_tokio_async_writer(Vec::new());
serializer.serialize_triple(TripleRef::new(
NamedNodeRef::new("http://example.com#me")?,
rdf::TYPE,
NamedNodeRef::new("http://schema.org/Person")?,
)).await?;
serializer.serialize_triple(TripleRef::new(
NamedNodeRef::new("http://example.com#me")?,
NamedNodeRef::new("http://schema.org/name")?,
LiteralRef::new_language_tagged_literal_unchecked("Foo Bar", "en"),
)).await?;
assert_eq!(
b"\n\n\t\n\t\tFoo Bar\n\t\n",
serializer.finish().await?.as_slice()
);
```
```
--------------------------------
### Iterator for RdfXmlPrefixesIter
Source: https://docs.rs/oxrdfxml/latest/oxrdfxml/struct.RdfXmlPrefixesIter.html
RdfXmlPrefixesIter implements the Iterator trait, yielding items of type (&'a str, &'a str). The next method advances the iterator and returns the next prefix pair, while size_hint provides bounds on the remaining length.
```APIDOC
## Iterator for RdfXmlPrefixesIter
### Description
RdfXmlPrefixesIter implements the Iterator trait, yielding items of type (&'a str, &'a str). The next method advances the iterator and returns the next prefix pair, while size_hint provides bounds on the remaining length.
### Type Item
(&'a str, &'a str)
### Methods
#### next
- **Signature**: fn next(&mut self) -> Option
- **Description**: Advances the iterator and returns the next value.
#### size_hint
- **Signature**: fn size_hint(&self) -> (usize, Option)
- **Description**: Returns the bounds on the remaining length of the iterator.
```
--------------------------------
### Access base IRI with SliceRdfXmlParser::base_iri
Source: https://docs.rs/oxrdfxml/latest/oxrdfxml/struct.SliceRdfXmlParser.html
Shows how to retrieve the current base IRI. The base IRI is `None` at the beginning if none was provided, and becomes `Some("http://example.com/")` after reading the first triple when the XML declares `xml:base`.
```rust
use oxrdfxml::RdfXmlParser;
let file = r#"
"#;
let mut parser = RdfXmlParser::new().for_slice(file);
assert!(parser.base_iri().is_none()); // No base at the beginning because none has been given to the parser.
parser.next().unwrap()?; // We read the first triple
assert_eq!(parser.base_iri(), Some("http://example.com/")); // There is now a base IRI.
```
--------------------------------
### Check base IRI with RdfXmlParser::base_iri
Source: https://docs.rs/oxrdfxml/latest/src/oxrdfxml/parser.rs.html
Demonstrates how the base IRI is initially None and becomes Some after reading the first triple when xml:base is present. Uses RdfXmlParser::new().for_slice(file) and parser.base_iri().
```rust
use oxrdfxml::RdfXmlParser;
let file = r#"
"#;
let mut parser = RdfXmlParser::new().for_slice(file);
assert!(parser.base_iri().is_none()); // No base at the beginning because none has been given to the parser.
parser.next().unwrap()?; // We read the first triple
assert_eq!(parser.base_iri(), Some("http://example.com/")); // There is now a base IRI.
# Result::<_, Box>::Ok(())
```
--------------------------------
### RdfXmlSerializer::for_writer
Source: https://docs.rs/oxrdfxml/latest/oxrdfxml/struct.RdfXmlSerializer.html
Creates a writer that serializes RDF/XML to a synchronous Write implementation.
```APIDOC
## RdfXmlSerializer::for_writer
### Description
Serializes a RDF/XML file to a `Write` implementation. This writer does unbuffered writes.
### Method
`pub fn for_writer(self, writer: W) -> WriterRdfXmlSerializer`
### Parameters
- `writer` (W) - Required - The `Write` implementation to write the RDF/XML output to.
### Returns
`WriterRdfXmlSerializer` - A serializer that writes to the given writer.
### Example
```rust
use oxrdf::{NamedNodeRef, TripleRef};
use oxrdfxml::RdfXmlSerializer;
let mut serializer = RdfXmlSerializer::new()
.with_base_iri("http://example.com")?
.with_prefix("ex", "http://example.com/ns#")?
.for_writer(Vec::new());
serializer.serialize_triple(TripleRef::new(
NamedNodeRef::new("http://example.com#me")?,
NamedNodeRef::new("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")?,
NamedNodeRef::new("http://example.com/ns#Person")?,
))?;
serializer.serialize_triple(TripleRef::new(
NamedNodeRef::new("http://example.com#me")?,
NamedNodeRef::new("http://example.com/ns#parent")?,
NamedNodeRef::new("http://example.com#other")?,
))?;
assert_eq!(
b"\n\n\t\n\t\t\n\t\n",
serializer.finish()?.as_slice()
);
```
```
--------------------------------
### fn scan(self, initial_state: St, f: F) -> Scan
Source: https://docs.rs/oxrdfxml/latest/oxrdfxml/struct.SliceRdfXmlParser.html
An iterator adapter which, like fold, holds internal state, but unlike fold, produces a new iterator.
```APIDOC
## fn scan(self, initial_state: St, f: F) -> Scan
### Description
An iterator adapter which, like `fold`, holds internal state, but unlike `fold`, produces a new iterator.
### Method
`scan`
### Signature
rust
fn scan(self, initial_state: St, f: F) -> Scan
where
Self: Sized,
F: FnMut(&mut St, Self::Item) -> Option,
### Parameters
- **initial_state** (St) - Required - The initial state for the scan.
- **f** (F) - Required - A closure that takes the current state and an item, and returns an optional new item.
### Returns
- **Scan** - An iterator adapter that yields the results of the scan.
```
--------------------------------
### fn inspect(self, f: F) -> Inspect
Source: https://docs.rs/oxrdfxml/latest/oxrdfxml/struct.SliceRdfXmlParser.html
Does something with each element of an iterator, passing the value on.
```APIDOC
## fn inspect(self, f: F) -> Inspect
### Description
Does something with each element of an iterator, passing the value on.
### Method
`inspect`
### Signature
rust
fn inspect(self, f: F) -> Inspect
where
Self: Sized,
F: FnMut(&Self::Item),
### Parameters
- **f** (F) - Required - A closure that is called with a reference to each item.
### Returns
- **Inspect** - An iterator adapter that yields the original items after calling `f` on each.
```
--------------------------------
### fn reduce(self, f: F) -> Option
Source: https://docs.rs/oxrdfxml/latest/oxrdfxml/struct.SliceRdfXmlParser.html
Reduces the elements to a single one, by repeatedly applying a reducing operation.
```APIDOC
## fn reduce(self, f: F) -> Option
### Description
Reduces the elements to a single one, by repeatedly applying a reducing operation.
### Method
`reduce`
### Signature
rust
fn reduce(self, f: F) -> Option
where
Self: Sized,
F: FnMut(Self::Item, Self::Item) -> Self::Item,
### Parameters
- **f** (F) - Required - A closure that takes two items and returns a single item.
### Returns
- **Option** - The reduced value, or `None` if the iterator is empty.
```
--------------------------------
### prefixes
Source: https://docs.rs/oxrdfxml/latest/oxrdfxml/struct.TokioAsyncReaderRdfXmlParser.html
Returns an iterator over the IRI prefixes considered at the current step of parsing. The iterator yields (prefix name, prefix value) tuples.
```APIDOC
## prefixes
### Description
The list of IRI prefixes considered at the current step of the parsing. This method returns (prefix name, prefix value) tuples. It is empty at the beginning of the parsing and gets updated when prefixes are encountered. It should be full at the end of the parsing (but if a prefix is overridden, only the latest version will be returned).
### Method
pub fn prefixes(&self) -> RdfXmlPrefixesIter<'_>
### Parameters
- **self** (&TokioAsyncReaderRdfXmlParser) - Required - The parser instance.
### Returns
- **RdfXmlPrefixesIter<'_>** - An iterator over (prefix name, prefix value) tuples.
```
--------------------------------
### any
Source: https://docs.rs/oxrdfxml/latest/oxrdfxml/struct.RdfXmlPrefixesIter.html
Tests if any element of the iterator matches a predicate.
```APIDOC
## any
### Description
Tests if any element of the iterator matches a predicate.
### Method
fn any(&mut self, f: F) -> bool
### Parameters
- **f** (F) - Required - The predicate function.
### Constraints
- Self: Sized
- F: FnMut(Self::Item) -> bool
### Returns
bool - true if any element matches, false otherwise.
```
--------------------------------
### Test IRI splitting logic
Source: https://docs.rs/oxrdfxml/latest/src/oxrdfxml/serializer.rs.html
Verifies the behavior of the split_iri function with various IRI formats including standard URLs, fragments, and URNs.
```rust
#[test]
fn test_split_iri() {
assert_eq!(
split_iri("http://schema.org/Person"),
("http://schema.org/", "Person")
);
assert_eq!(split_iri("http://schema.org/"), ("http://schema.org/", ""));
assert_eq!(
split_iri("http://schema.org#foo"),
("http://schema.org#", "foo")
);
assert_eq!(split_iri("urn:isbn:foo"), ("urn:isbn:", "foo"));
}
```