Re: [xml] A question about parsing/reading DOCTYPE nodes.



On Mon, Nov 28, 2011 at 03:58:56PM +0100, Alexander Hugestrand wrote:
Hi,

I've had the following problem in both PHP and C++, and can't find
any relevant information about this. It should be quite simple
actually.

I am trying to parse an xml file, and my code works perfectly for
all node types except DOCTYPE nodes. But I can't find any
information about how to extract the information from it. Here is an
example (my goal is to retrieve the strings "PublicIdentifier" and
"URIreference"):

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE test PUBLIC "PublicIdentifier" "URIreference">
<test>
</test>

Here is some code that illustrates my approach, using an
xmlTextReader
<http://www.xmlsoft.org/html/libxml-xmlreader.html#xmlTextReader>:

*while*(xmlTextReaderRead(myXmlReader) == 1) {
// Why does xmlTextReaderNodeType() return an int and not an enum?
        xmlReaderTypes nodeType =
(xmlReaderTypes)xmlTextReaderNodeType(myXmlReader);
*switch*(nodeType) {
*case *XML_READER_TYPE_ELEMENT: /* Do something */ *break*;
*case *XML_READER_TYPE_END_ELEMENT: /* Do something */ *break*;
*case *XML_READER_TYPE_TEXT: /* Do something */ *break*;
*case *XML_READER_TYPE_CDATA: /* Do something */ *break*;
*case *XML_READER_TYPE_PROCESSING_INSTRUCTION: /* Do something */ *break*;
*case *XML_READER_TYPE_COMMENT: /* Do something */ *break*;
            // ...
*case *XML_READER_TYPE_DOCUMENT_TYPE: {
// What do I do here?

  Get the underlying xmlNodePtr
  http://xmlsoft.org/html/libxml-xmlreader.html#xmlTextReaderCurrentNode
make sure it's type is XML_DTD_NODE, and then cast it to a
xmlDtdPtr, then look at SystemID and ExternalID fields,

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]