Re: [xml] referencing to parameter entity



On 2004-04-03 14.23.27, Daniel Veillard wrote:
On Sat, Apr 03, 2004 at 02:02:48PM +0200, Furucz Janos wrote:
[...]
> I need to create a doc that starts like this:
> <?xml version="1.0"?>
> <!DOCTYPE IDMEF-Message PUBLIC "-//IETF//DTD RFC XXXX IDMEF
v1.0//EN"
> "/usr/local/share/snort/idmef-message.dtd" [
> <!ENTITY % x-fwmessage SYSTEM "/usr/local/share/snort/fw-message. dtd">
> %x-fwmessage;
> ]>
> ...
>
> I can add the external dtd to the doc as parameter entity with
> xmlAddDocEntity(doc, FWDTD_NAME, XML_EXTERNAL_PARAMETER_ENTITY,
NULL,
> FWDTD_PATH, NULL);
> function.
>
> This function generates this doc:
> <?xml version="1.0"?>
> <!DOCTYPE IDMEF-Message PUBLIC "-//IETF//DTD RFC XXXX IDMEF
v1.0//EN"
> "/usr/local/share/snort/idmef-message.dtd" [
> <!ENTITY % x-fwmessage SYSTEM "/usr/local/share/snort/fw-message. dtd">
> ]>
> ...
>
> My question is, how can I create the "%x-fwmessage;" reference.
> Sorry about the question if it is trivial, but I'm new in xml.

Hum, there is an hackish way to do this by adding a text node to the DTD children of the document, based on xmlNewText() and xmlAddChild (),
here is a python based example:

>>> doc = libxml2.parseFile("tst.xml")
>>> print doc.serialize()
<?xml version="1.0"?>
<!DOCTYPE IDMEF-Message PUBLIC "-//IETF//DTD RFC XXXX IDMEF v1.0//EN"
"/usr/local/share/snort/idmef-message.dtd" [
<!ENTITY % x-fwmessage SYSTEM "/usr/local/share/snort/fw-message. dtd">
]>
<IDMEF-Message/>

>>> dtd = doc.children
>>> text = libxml2.newText('%x-fwmessage;\n')
>>> dtd.addChild(text)
<xmlNode (text) object at 0x81f7fec>
>>> print doc.serialize()
<?xml version="1.0"?>
<!DOCTYPE IDMEF-Message PUBLIC "-//IETF//DTD RFC XXXX IDMEF v1.0//EN"
"/usr/local/share/snort/idmef-message.dtd" [
<!ENTITY % x-fwmessage SYSTEM "/usr/local/share/snort/fw-message. dtd">
%x-fwmessage;
]>
<IDMEF-Message/>

>>>

Daniel

--
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit
http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



Thank you many times

It works in C like this:

void appendFWDtd(xmlDocPtr doc) {
        
        xmlEntityPtr fwdtdptr;
        xmlNodePtr docchildptr, fwreftextptr;
        
        fwdtdptr = xmlAddDocEntity(doc,
                FWDTD_NAME,
                XML_EXTERNAL_PARAMETER_ENTITY,
                NULL,
                FWDTD_PATH,
                NULL);

        fwreftextptr = xmlNewText((xmlChar *) FWDTD_REF);
        docchildptr = doc->children;
        xmlAddChild(docchildptr, fwreftextptr);
}

JOhn,
jhn freemail hu



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