| 1 | /////////////////////////////////////////////////////////////////////////////// |
| 2 | // Copyright (c) 2000-2014 Ericsson Telecom AB |
| 3 | // All rights reserved. This program and the accompanying materials |
| 4 | // are made available under the terms of the Eclipse Public License v1.0 |
| 5 | // which accompanies this distribution, and is available at |
| 6 | // http://www.eclipse.org/legal/epl-v10.html |
| 7 | /////////////////////////////////////////////////////////////////////////////// |
| 8 | #include "ReadXml.hh" |
| 9 | #include "XmlReader.hh" |
| 10 | //#include "libxml/xmlreader.h" |
| 11 | |
| 12 | namespace ReadXml { |
| 13 | |
| 14 | static XmlReaderWrap *reader; |
| 15 | |
| 16 | INTEGER FromMemory(const OCTETSTRING& o) |
| 17 | { |
| 18 | if (reader != 0) { |
| 19 | TTCN_warning("Dangling XML reader encountered"); |
| 20 | delete reader; |
| 21 | } |
| 22 | TTCN_Buffer buf(o); |
| 23 | reader = new XmlReaderWrap(buf); |
| 24 | return 0; |
| 25 | } |
| 26 | |
| 27 | void Cleanup() |
| 28 | { |
| 29 | if (reader == 0) TTCN_error("XML reader not created"); |
| 30 | delete reader; |
| 31 | reader = 0; |
| 32 | } |
| 33 | |
| 34 | INTEGER XmlRead() |
| 35 | { |
| 36 | if (reader == 0) TTCN_error("XML reader not created"); |
| 37 | return reader->Read(); |
| 38 | } |
| 39 | |
| 40 | xmlReaderTypes NodeType() |
| 41 | { |
| 42 | if (reader == 0) TTCN_error("XML reader not created"); |
| 43 | return reader->NodeType(); |
| 44 | } |
| 45 | |
| 46 | INTEGER Depth() |
| 47 | { |
| 48 | if (reader == 0) TTCN_error("XML reader not created"); |
| 49 | return reader->Depth(); |
| 50 | } |
| 51 | |
| 52 | CHARSTRING Name() |
| 53 | { |
| 54 | if (reader == 0) TTCN_error("XML reader not created"); |
| 55 | return (const char*)reader->Name(); |
| 56 | } |
| 57 | |
| 58 | CHARSTRING Value() |
| 59 | { |
| 60 | if (reader == 0) TTCN_error("XML reader not created"); |
| 61 | return (const char*)reader->Value(); |
| 62 | } |
| 63 | |
| 64 | CHARSTRING NsUri() |
| 65 | { |
| 66 | if (reader == 0) TTCN_error("XML reader not created"); |
| 67 | return (const char*)reader->NamespaceUri(); // NUL results in empty string |
| 68 | } |
| 69 | |
| 70 | // attribute handling |
| 71 | |
| 72 | INTEGER FirstAttribute() |
| 73 | { |
| 74 | if (reader == 0) TTCN_error("XML reader not created"); |
| 75 | return reader->MoveToFirstAttribute(); |
| 76 | } |
| 77 | |
| 78 | INTEGER NextAttribute() |
| 79 | { |
| 80 | if (reader == 0) TTCN_error("XML reader not created"); |
| 81 | return reader->MoveToNextAttribute(); |
| 82 | } |
| 83 | |
| 84 | } |