| 158 | } |
| 159 | |
| 160 | int vtkXMLTreeReader::RequestData( |
| 161 | vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector) |
| 162 | { |
| 163 | if (!this->FileName && !this->XMLString) |
| 164 | { |
| 165 | vtkErrorMacro("A FileName or XMLString must be specified"); |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | xmlDoc* doc = nullptr; |
| 170 | if (this->FileName) |
| 171 | { |
| 172 | // Parse the file and get the DOM |
| 173 | doc = xmlReadFile(this->FileName, nullptr, 0); |
| 174 | } |
| 175 | else if (this->XMLString) |
| 176 | { |
| 177 | // Parse from memory and get the DOM |
| 178 | doc = xmlReadMemory( |
| 179 | this->XMLString, static_cast<int>(strlen(this->XMLString)), "noname.xml", nullptr, 0); |
| 180 | } |
| 181 | |
| 182 | // Store the XML hierarchy into a vtkMutableDirectedGraph, |
| 183 | // later to be placed in a vtkTree. |
| 184 | vtkSmartPointer<vtkMutableDirectedGraph> builder = |
| 185 | vtkSmartPointer<vtkMutableDirectedGraph>::New(); |
| 186 | |
| 187 | vtkDataSetAttributes* data = builder->GetVertexData(); |
| 188 | |
| 189 | if (this->ReadTagName) |
| 190 | { |
| 191 | vtkStringArray* nameArr = vtkStringArray::New(); |
| 192 | nameArr->SetName(vtkXMLTreeReader::TagNameField); |
| 193 | data->AddArray(nameArr); |
| 194 | nameArr->Delete(); |
| 195 | } |
| 196 | |
| 197 | if (this->ReadCharData) |
| 198 | { |
| 199 | vtkStringArray* charArr = vtkStringArray::New(); |
| 200 | charArr->SetName(vtkXMLTreeReader::CharDataField); |
| 201 | data->AddArray(charArr); |
| 202 | charArr->Delete(); |
| 203 | } |
| 204 | |
| 205 | // Get the root element node |
| 206 | xmlNode* rootElement = xmlDocGetRootElement(doc); |
| 207 | if (!rootElement) |
| 208 | { |
| 209 | vtkErrorMacro(<< "Could not get root element of document."); |
| 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | vtkXMLTreeReaderProcessElement(builder, -1, rootElement, this->ReadCharData, this->MaskArrays); |
| 214 | |
| 215 | xmlFreeDoc(doc); |
| 216 | |
| 217 | // Make all the arrays the same size |
nothing calls this directly
no test coverage detected