Aracılığıyla paylaş


XmlReader Class

  • java.lang.Object
    • com.azure.xml.XmlReader

Implements

public abstract class XmlReader
implements AutoCloseable

Reads an XML encoded value as a stream of tokens.

Constructor Summary

Constructor Description
XmlReader()

Creates an instance of XmlReader.

Method Summary

Modifier and Type Method and Description
final T getNullableAttribute(String namespaceUri, String localName, ReadValueCallback<String,T> converter)

Gets the nullable value for the attribute in the XML element.

final T getNullableElement(ReadValueCallback<String,T> converter)

Gets the nullable value for the current element.

final T readObject(String localName, ReadValueCallback<XmlReader,T> converter)

Reads an object from the XML stream.

final T readObject(String namespaceUri, String localName, ReadValueCallback<XmlReader,T> converter)

Reads an object from the XML stream.

abstract void close()

Closes the XML stream.

abstract XmlToken currentToken()

Gets the XmlToken that the reader points to currently.

final byte[] getBinaryAttribute(String namespaceUri, String localName)

Gets the binary value for the attribute in the XML element.

final byte[] getBinaryElement()

Gets the binary value for the current element.

final boolean getBooleanAttribute(String namespaceUri, String localName)

Gets the boolean value for the attribute in the XML element.

final boolean getBooleanElement()

Gets the boolean value for the current element.

final double getDoubleAttribute(String namespaceUri, String localName)

Gets the double value for the attribute in the XML element.

final double getDoubleElement()

Gets the double value for the current element.

abstract QName getElementName()

Gets the QName for the current XML element.

final float getFloatAttribute(String namespaceUri, String localName)

Gets the float value for the attribute in the XML element.

final float getFloatElement()

Gets the float value for the current element.

final int getIntAttribute(String namespaceUri, String localName)

Gets the int value for the attribute in the XML element.

final int getIntElement()

Gets the int value for the current element.

final long getLongAttribute(String namespaceUri, String localName)

Gets the long value for the attribute in the XML element.

final long getLongElement()

Gets the long value for the current element.

abstract String getStringAttribute(String namespaceUri, String localName)

Gets the string value for the attribute in the XML element.

abstract String getStringElement()

Gets the string value for the current element.

abstract XmlToken nextElement()

Iterates to and returns the next START_ELEMENT or END_ELEMENT in the XML stream.

final void skipElement()

Skips the current XML element.

Methods inherited from java.lang.Object

Constructor Details

XmlReader

public XmlReader()

Creates an instance of XmlReader.

Method Details

getNullableAttribute

public final T getNullableAttribute(String namespaceUri, String localName, ReadValueCallback converter)

Gets the nullable value for the attribute in the XML element.

If the attribute doesn't have a value or doesn't exist null will be returned, otherwise the attribute getStringAttribute(String namespaceUri, String localName) is passed to the converter.

Parameters:

namespaceUri - Attribute namespace, may be null.
localName - Attribute local name.
converter - Function that converts the attribute text value to the nullable type.

Returns:

The converted text value, or null if the attribute didn't have a value.

Throws:

XMLStreamException

- If the nullable attribute cannot be read.

getNullableElement

public final T getNullableElement(ReadValueCallback converter)

Gets the nullable value for the current element.

If the current element doesn't have a value null will be returned, otherwise the element getStringElement() is passed to the converter.

Parameters:

converter - Function that converts the element text value to the nullable type.

Returns:

The converted text value, or null if the element didn't have a value.

Throws:

XMLStreamException

- If the nullable element cannot be read.

readObject

public final T readObject(String localName, ReadValueCallback converter)

Reads an object from the XML stream.

Validates that the XmlReader is currently pointing to an START_ELEMENT which has the qualifying name specified by the startTagName.

Parameters:

localName - The expecting starting local name for the object.
converter - The function that reads the object.

Returns:

An instance of the expected object,

Throws:

XMLStreamException

- If the starting tag isn't XmlToken#START_ELEMENT or the tag doesn't match the expected startTagName

readObject

public final T readObject(String namespaceUri, String localName, ReadValueCallback converter)

Reads an object from the XML stream.

Validates that the XmlReader is currently pointing to an START_ELEMENT which has the qualifying name specified by the startTagName.

Parameters:

namespaceUri - The expecting namespace for the object.
localName - The expecting starting local name for the object.
converter - The function that reads the object.

Returns:

An instance of the expected object,

Throws:

XMLStreamException

- If the starting tag isn't XmlToken#START_ELEMENT or the tag doesn't match the expected startTagName

close

public abstract void close()

Closes the XML stream.

Throws:

XMLStreamException

- If the underlying content store fails to close.

currentToken

public abstract XmlToken currentToken()

Gets the XmlToken that the reader points to currently.

Returns START_DOCUMENT if the reader hasn't begun reading the XML stream. Returns END_DOCUMENT if the reader has completed reading the XML stream.

Returns:

The XmlToken that the reader points to currently.

getBinaryAttribute

public final byte[] getBinaryAttribute(String namespaceUri, String localName)

Gets the binary value for the attribute in the XML element.

Parameters:

namespaceUri - Attribute namespace, may be null.
localName - Attribute local name.

Returns:

The binary value for the attribute in the XML element.

getBinaryElement

public final byte[] getBinaryElement()

Gets the binary value for the current element.

Returns:

The binary value for the current element.

Throws:

XMLStreamException

- If the binary element cannot be read.

getBooleanAttribute

public final boolean getBooleanAttribute(String namespaceUri, String localName)

Gets the boolean value for the attribute in the XML element.

Parameters:

namespaceUri - Attribute namespace, may be null.
localName - Attribute local name.

Returns:

The boolean value for the attribute in the XML element.

getBooleanElement

public final boolean getBooleanElement()

Gets the boolean value for the current element.

Returns:

The boolean value for the current element.

Throws:

XMLStreamException

- If the boolean element cannot be read.

getDoubleAttribute

public final double getDoubleAttribute(String namespaceUri, String localName)

Gets the double value for the attribute in the XML element.

Parameters:

namespaceUri - Attribute namespace, may be null.
localName - Attribute local name.

Returns:

The double value for the attribute in the XML element.

getDoubleElement

public final double getDoubleElement()

Gets the double value for the current element.

Returns:

The double value for the current element.

Throws:

XMLStreamException

- If the double element cannot be read.

getElementName

public abstract QName getElementName()

Gets the QName for the current XML element.

Returns:

The QName for the current XML element.

getFloatAttribute

public final float getFloatAttribute(String namespaceUri, String localName)

Gets the float value for the attribute in the XML element.

Parameters:

namespaceUri - Attribute namespace, may be null.
localName - Attribute local name.

Returns:

The float value for the attribute in the XML element.

getFloatElement

public final float getFloatElement()

Gets the float value for the current element.

Returns:

The float value for the current element.

Throws:

XMLStreamException

- If the float element cannot be read.

getIntAttribute

public final int getIntAttribute(String namespaceUri, String localName)

Gets the int value for the attribute in the XML element.

Parameters:

namespaceUri - Attribute namespace, may be null.
localName - Attribute local name.

Returns:

The int value for the attribute in the XML element.

getIntElement

public final int getIntElement()

Gets the int value for the current element.

Returns:

The int value for the current element.

Throws:

XMLStreamException

- If the int element cannot be read.

getLongAttribute

public final long getLongAttribute(String namespaceUri, String localName)

Gets the long value for the attribute in the XML element.

Parameters:

namespaceUri - Attribute namespace, may be null.
localName - Attribute local name.

Returns:

The long value for the attribute in the XML element.

getLongElement

public final long getLongElement()

Gets the long value for the current element.

Returns:

The long value for the current element.

Throws:

XMLStreamException

- If the long element cannot be read.

getStringAttribute

public abstract String getStringAttribute(String namespaceUri, String localName)

Gets the string value for the attribute in the XML element.

Null is returned if the attribute doesn't exist in the XML element.

Parameters:

namespaceUri - Attribute namespace, may be null.
localName - Attribute local name.

Returns:

The string value for the attribute in the XML element, or null if the attribute doesn't exist.

getStringElement

public abstract String getStringElement()

Gets the string value for the current element.

Returns:

The string value for the current element.

Throws:

XMLStreamException

- If the String element cannot be read.

nextElement

public abstract XmlToken nextElement()

Iterates to and returns the next START_ELEMENT or END_ELEMENT in the XML stream.

Returns END_DOCUMENT if iterating to the next element token completes reading of the XML stream.

Returns:

The next START_ELEMENT or END_ELEMENT in the XML stream, or END_DOCUMENT if reading completes.

Throws:

XMLStreamException

- If the next element cannot be determined.

skipElement

public final void skipElement()

Skips the current XML element.

If the currentToken() isn't an START_ELEMENT this is a no-op.

This reads the XML stream until the matching END_ELEMENT is found for the current START_ELEMENT.

Throws:

XMLStreamException

- If skipping the element fails.

Applies to