1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/parser/xml/Node.h
12 #ifndef ZYPP_PARSER_XML_NODE_H
13 #define ZYPP_PARSER_XML_NODE_H
17 #include <zypp/parser/xml/XmlString.h>
19 ///////////////////////////////////////////////////////////////////
21 { /////////////////////////////////////////////////////////////////
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////
30 /** xmlTextReader based interface to \ref Reader's current node.
31 * Node provides xmlTextReader methods that do not change
32 * the readers position in the file. Mostly access to the
41 /** Ctor referencing a \ref Reader. */
42 Node( xmlTextReaderPtr const & reader_r );
44 /** Validate Node in a boolean context. */
45 explicit operator bool() const
49 /** Provides the number of attributes of the current node. */
50 int attributeCount() const
51 { return xmlTextReaderAttributeCount( _reader ); }
53 /** The base URI of the node. */
54 XmlString baseUri() const
55 { return xmlTextReaderConstBaseUri( _reader ); }
57 /** Provide the column number of the current parsing point. */
58 int columnNumber() const
59 { return xmlTextReaderGetParserColumnNumber( _reader ); }
61 /** The depth of the node in the tree. */
63 { return xmlTextReaderDepth( _reader ); }
65 /** Determine the encoding of the document being read. */
66 XmlString encoding() const
67 { return xmlTextReaderConstEncoding( _reader ); }
69 /** Provides a copy of the attribute value with the specified
71 XmlString getAttribute( const char * name_r ) const
72 { return XmlString( xmlTextReaderGetAttribute( _reader, reinterpret_cast<const xmlChar *>(name_r) ),
75 XmlString getAttribute( const std::string & name_r ) const
76 { return getAttribute( name_r.c_str() ); }
78 /** Provides a copy of the attribute value with the specified
79 * index relative to the containing element. */
80 XmlString getAttributeNo( int no_r ) const
81 { return XmlString( xmlTextReaderGetAttributeNo( _reader, no_r ), XmlString::FREE ); }
83 /** Whether the node has attributes. */
84 int hasAttributes() const
85 { return xmlTextReaderHasAttributes( _reader ); }
87 /** Whether the node can have a text value. */
89 { return xmlTextReaderHasValue( _reader ); }
91 /** Whether this is an Attribute node. */
92 bool isAttribute() const
93 { return( nodeType() == XML_READER_TYPE_ATTRIBUTE ); }
95 /** Whether an Attribute node was generated from the default value
96 * defined in the DTD or schema. */
98 { return xmlTextReaderIsDefault( _reader ); }
100 /** Check if the current node is empty. */
101 int isEmptyElement() const
102 { return xmlTextReaderIsEmptyElement( _reader ); }
104 /** Determine whether the current node is a namespace declaration
105 * rather than a regular attribute.*/
106 int isNamespaceDecl() const
107 { return xmlTextReaderIsNamespaceDecl( _reader ); }
109 /** Provide the line number of the current parsing point. */
110 int lineNumber() const
111 { return xmlTextReaderGetParserLineNumber( _reader ); }
113 /** The local name of the node. */
114 XmlString localName() const
115 { return xmlTextReaderConstLocalName( _reader ); }
117 /** The qualified name of the node, equal to Prefix :LocalName. */
118 XmlString name() const
119 { return xmlTextReaderConstName( _reader ); }
121 /** The URI defining the namespace associated with the node. */
122 XmlString namespaceUri() const
123 { return xmlTextReaderConstNamespaceUri( _reader ); }
125 /** Get the node type of the current node. */
126 NodeType nodeType() const
127 { return (NodeType)xmlTextReaderNodeType( _reader ); }
129 /** A shorthand reference to the namespace associated with the node. */
130 XmlString prefix() const
131 { return xmlTextReaderConstPrefix( _reader ); }
133 /** The quotation mark character used to enclose the value of an attribute.
134 * \return \c " or \c ' or -1 in case of error. */
135 int quoteChar() const
136 { return xmlTextReaderQuoteChar( _reader ); }
138 /** Gets the read state of the reader. */
139 ReadState readState() const
140 { return (ReadState)xmlTextReaderReadState( _reader ); }
142 /** Provides the text value of the node if present. */
143 XmlString value() const
144 { return xmlTextReaderConstValue( _reader ); }
146 /** Provides a copy of the text value of the node if present. */
147 XmlString getValue() const
148 { return XmlString( xmlTextReaderValue( _reader ), XmlString::FREE ); }
150 /** The xml:lang scope within which the node resides. */
151 XmlString xmlLang() const
152 { return xmlTextReaderConstXmlLang( _reader ); }
154 /** Determine the XML version of the document being read. */
155 XmlString xmlVersion() const
156 { return xmlTextReaderConstXmlVersion( _reader ); }
159 /** NULL Reader referenced by default ctor. */
160 static xmlTextReaderPtr const _no_reader;
161 /** Reference to the \ref Reader. */
162 xmlTextReaderPtr const & _reader;
164 ///////////////////////////////////////////////////////////////////
166 /** \relates Node Stream output. */
167 std::ostream & operator<<( std::ostream & str, const Node & obj );
169 /////////////////////////////////////////////////////////////////
171 ///////////////////////////////////////////////////////////////////
172 /////////////////////////////////////////////////////////////////
174 ///////////////////////////////////////////////////////////////////
175 #endif // ZYPP_PARSER_XML_NODE_H