[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-libs-commits] CVS: libxmlsharp/dotgnu.xml Native.cs,NONE,1.1 Xml
From: |
Gopal.V <address@hidden> |
Subject: |
[Dotgnu-libs-commits] CVS: libxmlsharp/dotgnu.xml Native.cs,NONE,1.1 XmlAttr.cs,NONE,1.1 XmlCData.cs,NONE,1.1 XmlComment.cs,NONE,1.1 XmlDoc.cs,NONE,1.1 XmlElement.cs,NONE,1.1 XmlElementType.cs,NONE,1.1 XmlNodeCache.cs,NONE,1.1 XmlNode.cs,NONE,1.1 XmlNodeEnumerator.cs,NONE,1.1 XmlNodeFactory.cs,NONE,1.1 XmlNodeList.cs,NONE,1.1 XmlNs.cs,NONE,1.1 XmlParser.cs,NONE,1.1 XmlPI.cs,NONE,1.1 XmlText.cs,NONE,1.1 Makefile,NONE,1.1 |
Date: |
Thu, 04 Jul 2002 19:44:36 -0400 |
Update of /cvsroot/dotgnu-libs/libxmlsharp/dotgnu.xml
In directory subversions:/tmp/cvs-serv12573/dotgnu.xml
Added Files:
Native.cs XmlAttr.cs XmlCData.cs XmlComment.cs XmlDoc.cs
XmlElement.cs XmlElementType.cs XmlNodeCache.cs XmlNode.cs
XmlNodeEnumerator.cs XmlNodeFactory.cs XmlNodeList.cs XmlNs.cs
XmlParser.cs XmlPI.cs XmlText.cs Makefile
Log Message:
First Post
--- NEW FILE ---
/*
* Native.cs - PInvoke calls for libxml_wrapper
*
* Copyright (C) 2002 Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using System;
namespace dotgnu.xml
{
internal class Native
{
[DllImport("libxml_wrapper.so")]
internal static extern IntPtr _xmlParseFile(String file);
[DllImport("libxml_wrapper.so")]
internal static extern IntPtr _xmlParseMemory(String file,int size);
[DllImport("libxml_wrapper.so")]
internal static extern XmlElementType _xmlNodeGetElementType(IntPtr
node);
[DllImport("libxml_wrapper.so")]
internal static extern String _xmlNodeGetName(IntPtr node);
[DllImport("libxml_wrapper.so")]
internal static extern IntPtr _xmlNodeGetNs(IntPtr node);
/* Navigation */
[DllImport("libxml_wrapper.so")]
internal static extern IntPtr _xmlNodeGetPrevSibling(IntPtr node);
[DllImport("libxml_wrapper.so")]
internal static extern IntPtr _xmlNodeGetNextSibling(IntPtr node);
[DllImport("libxml_wrapper.so")]
internal static extern IntPtr _xmlNodeGetFirstChild(IntPtr node);
[DllImport("libxml_wrapper.so")]
internal static extern IntPtr _xmlNodeGetLastChild(IntPtr node);
[DllImport("libxml_wrapper.so")]
internal static extern IntPtr _xmlNodeGetDocument(IntPtr node);
[DllImport("libxml_wrapper.so")]
internal static extern IntPtr _xmlElementGetFirstAttr(IntPtr node);
/* String Dumpers */
[DllImport("libxml_wrapper.so")]
internal static extern String _xmlNodeDump(IntPtr node,int level
,int format);
[DllImport("libxml_wrapper.so")]
internal static extern String _xmlDocDump(IntPtr doc,int format);
[DllImport("libxml_wrapper.so")]
internal static extern String _xmlNodeGetContent(IntPtr node);
/* Namespaces */
[DllImport("libxml_wrapper.so")]
internal static extern String _xmlNsGetHref(IntPtr ns);
[DllImport("libxml_wrapper.so")]
internal static extern String _xmlNsGetPrefix(IntPtr ns);
/* Attributes */
[DllImport("libxml_wrapper.so")]
internal static extern String _xmlElementGetAttrValue(IntPtr node,
String name);
[DllImport("libxml_wrapper.so")]
internal static extern IntPtr _xmlElementGetAttr(IntPtr node,
String name);
[DllImport("libxml_wrapper.so")]
internal static extern int _xmlElementSetAttrValue(IntPtr node,
String name,String value);
[DllImport("libxml_wrapper.so")]
internal static extern IntPtr _xmlElementSetAttr(IntPtr node,
String name,String value);
/* Cache nodes to prevent double freeing */
[DllImport("libxml_wrapper.so")]
internal static extern bool _xmlNodeCache(IntPtr node,Object nodeObj);
[DllImport("libxml_wrapper.so")]
internal static extern bool _xmlNodeUncache(IntPtr node);
[DllImport("libxml_wrapper.so")]
internal static extern bool _xmlNodeIsCached(IntPtr node);
[DllImport("libxml_wrapper.so")]
internal static extern Object _xmlNodeGetCached(IntPtr node);
/* object construction */
[DllImport("libxml_wrapper.so")]
internal static extern IntPtr _xmlNewDoc(String version);
[DllImport("libxml_wrapper.so")]
internal static extern IntPtr _xmlNewNode(IntPtr ns,String name);
[DllImport("libxml_wrapper.so")]
internal static extern IntPtr _xmlNewText(String content);
[DllImport("libxml_wrapper.so")]
internal static extern IntPtr _xmlNewCDataBlock(String content,int len);
[DllImport("libxml_wrapper.so")]
internal static extern IntPtr _xmlNewComment(String content);
[DllImport("libxml_wrapper.so")]
internal static extern IntPtr _xmlNewPI(String name,String content);
/* Adding to the tree */
[DllImport("libxml_wrapper.so")]
internal static extern IntPtr _xmlAddChild(IntPtr parent,IntPtr child);
/* adjusting the tree */
[DllImport("libxml_wrapper.so")]
internal static extern void _xmlNodeNormalize(IntPtr node);
/* compression support ie my favourite */
[DllImport("libxml_wrapper.so")]
internal static extern int _xmlDocGetCompression(IntPtr doc);
[DllImport("libxml_wrapper.so")]
internal static extern int _xmlParserGetCompression();
[DllImport("libxml_wrapper.so")]
internal static extern void _xmlDocSetCompression(IntPtr doc,int level);
[DllImport("libxml_wrapper.so")]
internal static extern void _xmlParserSetCompression(int gzip);
/* file output */
[DllImport("libxml_wrapper.so")]
internal static extern void _xmlDocSaveToFile(IntPtr doc,String
filename,
int format);
}
}
--- NEW FILE ---
/*
* XmlAttr.cs - XmlAttr class XML_NODE_ATTRIBUTE
*
* Copyright (C) 2002 Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using System;
namespace dotgnu.xml
{
public class XmlAttr:XmlNode
{
public XmlAttr(IntPtr dataPtr):base(dataPtr);
public String Value
{
get
{
return
Native._xmlNodeDump(Native._xmlNodeGetFirstChild(dataPtr)
,0,0);
}
}
public XmlNs Namespace
{
get
{
IntPtr retval=Native._xmlNodeGetNs(dataPtr);
if(retval==IntPtr.Zero)
{
return null;
}
return new XmlNs(retval);
}
}
}
}
--- NEW FILE ---
/*
* XmlCData.cs - XmlCData class
*
* Copyright (C) 2002 Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using System;
namespace dotgnu.xml
{
public class XmlCData : XmlNode
{
internal XmlCData(IntPtr dataPtr):base(dataPtr);
public XmlCData(String content)
{
dataPtr=Native._xmlNewCDataBlock(content,content.Length);
XmlNodeCache.Cache(dataPtr,this);
}
public override String Name
{
get
{
return "#CDATA";
}
}
}
}
--- NEW FILE ---
/*
* XmlComment.cs - XmlComment class
*
* Copyright (C) 2002 Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using System;
namespace dotgnu.xml
{
public class XmlComment:XmlNode
{
internal XmlComment(IntPtr dataPtr):base(dataPtr)
{
XmlNodeCache.Cache(dataPtr,this);
}
public XmlComment(String comment)
{
dataPtr=Native._xmlNewComment(comment);
XmlNodeCache.Cache(dataPtr,this);
}
public override String Name
{
get
{
return "#COMMENT";
}
}
}
}
--- NEW FILE ---
/*
* XmlDoc.cs - XmlDoc class
*
* Copyright (C) 2002 Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using System;
using System.Runtime.InteropServices;
namespace dotgnu.xml
{
public class XmlDoc : XmlNode
{
internal XmlDoc(IntPtr dataPtr):base(dataPtr)
{
XmlNodeCache.Cache(dataPtr,this);
}
public XmlDoc()
{
dataPtr=Native._xmlNewDoc("1.0");
XmlNodeCache.Cache(dataPtr,this);
}
public XmlDoc(String xmlVersion)
{
dataPtr=Native._xmlNewDoc(xmlVersion);
}
public XmlNode AddChild(XmlNode child)
{
// clear the cache as this /might/ be freed !
// I ain't taking no chances. (wild wild west)
if(this.GetFirstChild()!=null)
{
throw new Exception("Cannot add more that one child to
a XmlDoc");
}
if(child.ElementType==XmlElementType.XML_TEXT_NODE)
XmlNodeCache.Uncache(child.DeSerialize());
IntPtr retval=Native._xmlAddChild(dataPtr,child.DeSerialize());
if(retval == IntPtr.Zero)
{
throw new Exception("New node Could not be linked in
!");
}
return XmlNodeFactory.NewNode(retval);
}
public void SaveToFile(String filename,int format)
{
Native._xmlDocSaveToFile(dataPtr,filename,format);
}
public void SaveToFile(String filename)
{
this.SaveToFile(filename,0);
}
public override String DumpXml()
{
return Native._xmlDocDump(dataPtr,1);
}
public override String DumpXml(int format)
{
return Native._xmlDocDump(dataPtr,format);
}
public int Compression
{
get
{
return Native._xmlDocGetCompression(dataPtr);
}
set
{
Native._xmlDocSetCompression(dataPtr,value);
}
}
public override String Name
{
get
{
return "#DOCUMENT";
}
}
}
}
--- NEW FILE ---
/*
* XmlNode.cs - XmlNode base class
*
* Copyright (C) 2002 Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using System;
namespace dotgnu.xml
{
public class XmlElement:XmlNode
{
public XmlElement(String name)
{
// pass a null namespace along
dataPtr=Native._xmlNewNode(IntPtr.Zero,name);
}
public XmlElement(IntPtr dataPtr):base(dataPtr)
{
XmlNodeCache.Cache(dataPtr,this);
}
public XmlNode AddChild(XmlNode child)
{
if(child.ElementType == XmlElementType.XML_DOCUMENT_NODE)
{
throw new Exception("Document nodes cannot be added
anywhere !");
}
// clear the cache as this /might/ be freed !
// I don't take no chances. (wild wild west)
if(child.ElementType == XmlElementType.XML_TEXT_NODE)
XmlNodeCache.Uncache(child.DeSerialize());
IntPtr retval=Native._xmlAddChild(dataPtr,child.DeSerialize());
if(retval == IntPtr.Zero)
{
throw new Exception("New node Could not be linked in
!");
}
return XmlNodeFactory.NewNode(retval);
}
public override String FQName
{
get
{
if(this.Namespace!=null)
{
return this.Namespace.Prefix+":"+this.Name;
}
return this.Name;
}
}
public String GetAttr(String name)
{
return Native._xmlElementGetAttrValue(dataPtr,name);
}
public void SetAttr(String name,String value)
{
Native._xmlElementSetAttrValue(dataPtr,name,value);
}
public XmlNodeList Attributes
{
get
{
IntPtr ptr=Native._xmlElementGetFirstAttr(dataPtr);
return new XmlNodeList(ptr);
}
}
public XmlNs Namespace
{
get
{
IntPtr retval=Native._xmlNodeGetNs(dataPtr);
if(retval==IntPtr.Zero)
{
return null;
}
return new XmlNs(retval);
}
}
}
}
--- NEW FILE ---
/*
* XmlElementType.cs - XmlElementType enum
*
* Copyright (C) 2002 Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace dotgnu.xml
{
public enum XmlElementType
{
XML_ELEMENT_UNDEF= 0,
XML_ELEMENT_NODE= 1,
XML_ATTRIBUTE_NODE= 2,
XML_TEXT_NODE= 3,
XML_CDATA_SECTION_NODE= 4,
XML_ENTITY_REF_NODE= 5,
XML_ENTITY_NODE= 6,
XML_PI_NODE= 7,
XML_COMMENT_NODE= 8,
XML_DOCUMENT_NODE= 9,
XML_DOCUMENT_TYPE_NODE= 10,
XML_DOCUMENT_FRAG_NODE= 11,
XML_NOTATION_NODE= 12,
XML_HTML_DOCUMENT_NODE= 13,
XML_DTD_NODE= 14,
XML_ELEMENT_DECL= 15,
XML_ATTRIBUTE_DECL= 16,
XML_ENTITY_DECL= 17,
XML_NAMESPACE_DECL= 18,
XML_XINCLUDE_START= 19,
XML_XINCLUDE_END= 20
}
}
--- NEW FILE ---
/*
* XmlNodeCache.cs - XmlNodeCache class
*
* Copyright (C) 2002 Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using System;
namespace dotgnu.xml
{
public abstract class XmlNodeCache
{
internal static bool IsCached(IntPtr ptr)
{
return Native._xmlNodeIsCached(ptr);
}
internal static bool Cache(IntPtr ptr,XmlNode node)
{
return Native._xmlNodeCache(ptr,node);
}
internal static bool Uncache(IntPtr ptr)
{
return Native._xmlNodeUncache(ptr);
}
internal static XmlNode GetCached(IntPtr ptr)
{
XmlNode retval=null;
#if DEBUG
if(!XmlNodeCache.IsCached(ptr))
{
throw new Exception("Node not registered ...");
}
#endif
retval=(XmlNode)(Native._xmlNodeGetCached(ptr));
return retval;
}
}
}
--- NEW FILE ---
/*
* XmlNode.cs - XmlNode base class
*
* Copyright (C) 2002 Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using System;
namespace dotgnu.xml
{
/* TODO : make this abstract after stubbing out all the classes */
public class XmlNode
{
protected IntPtr dataPtr;
protected String _name;
protected XmlElementType _elemType=XmlElementType.XML_ELEMENT_UNDEF;
protected String _rawXml=null;
protected XmlNodeList _children=null;
internal XmlNode() //ie to satisfy the inheritance
{
}
internal XmlNode(IntPtr ptr)
{
// do not Cache here ! , as we should prevent
// base() calls from interfering with the XmlNodeCache
// Cache only at first reference
dataPtr=ptr;
}
~XmlNode()
{
XmlNodeCache.Uncache(dataPtr);
}
public virtual XmlNode GetPreviousSibling()
{
IntPtr retval=Native._xmlNodeGetPrevSibling(dataPtr);
// actually I should use the this.DeSerialize() ,
// but what the heck, this is only FUN !
if(retval==IntPtr.Zero)
{
return null;
}
return XmlNodeFactory.NewNode(retval);
}
public virtual XmlNode GetNextSibling()
{
IntPtr retval=Native._xmlNodeGetNextSibling(dataPtr);
if(retval==IntPtr.Zero)
{
return null;
}
return XmlNodeFactory.NewNode(retval);
}
public virtual XmlNode GetFirstChild()
{
IntPtr retval=Native._xmlNodeGetFirstChild(dataPtr);
if(retval==IntPtr.Zero)
{
return null;
}
return XmlNodeFactory.NewNode(retval);
}
public virtual XmlNode GetLastChild()
{
IntPtr retval=Native._xmlNodeGetLastChild(dataPtr);
if(retval==IntPtr.Zero)
{
return null;
}
return XmlNodeFactory.NewNode(retval);
}
public XmlDoc GetDocument()
{
IntPtr retval=Native._xmlNodeGetDocument(dataPtr);
if(retval==IntPtr.Zero)
{
return null;
}
return (XmlDoc)(XmlNodeFactory.NewNode(retval));
}
public virtual String DumpXml()
{
if(_rawXml==null)
{
_rawXml=Native._xmlNodeDump(dataPtr,0,1);
}
return _rawXml;
}
public virtual String DumpXml(int format)
{
if(_rawXml==null)
{
_rawXml=Native._xmlNodeDump(dataPtr,0,format);
}
return _rawXml;
}
public virtual String DumpXml(int level,int format)
{
if(_rawXml==null)
{
_rawXml=Native._xmlNodeDump(dataPtr,level,format);
}
return _rawXml;
}
/*
* Ala Python , Note: base.ToString gives a nice type string ;)
*/
public String ShortString()
{
String data=this.DumpXml(0);
if(data.Length < 20)
return "<"+base.ToString()+"\""+ data+"\">";
String retval=data.Substring(0,12);
if(retval.Length == data.Length)
{
return retval;
}
for(int i=retval.Length;i<17;i++)
retval=retval+".";
retval=retval+data.Substring(data.Length-4,3);
return "<"+base.ToString()+" \""+retval+"\" >";
}
public void RemoveCachedEntries()
{
_name=null;
_rawXml=null;
_children=null;
}
public void Normalize()
{
foreach(XmlNode nd in this.Children)
{
nd.Normalize();
}
this.RemoveCachedEntries();
Native._xmlNodeNormalize(dataPtr);
}
internal IntPtr DeSerialize()
{
return dataPtr;
}
public virtual String Name
{
get
{
if(_name==null)
{
_name=Native._xmlNodeGetName(dataPtr);
}
return _name;
}
}
public virtual XmlNodeList Children
{
get
{
if(_children==null)
_children=new
XmlNodeList(Native._xmlNodeGetFirstChild(dataPtr));
return _children;
}
}
public virtual String Content
{
get
{
return Native._xmlNodeGetContent(dataPtr);
}
}
public virtual String FQName
{
get
{
return this.Name;
}
}
public virtual XmlElementType ElementType
{
get
{
if(_elemType==XmlElementType.XML_ELEMENT_UNDEF)
{
_elemType=Native._xmlNodeGetElementType(dataPtr);
}
return _elemType;
}
}
}
}
--- NEW FILE ---
/*
* XmlNodeEnumerator.cs
*
* Copyright (C) 2002 Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using System;
using System.Collections;
namespace dotgnu.xml
{
public class XmlNodeEnumerator : IEnumerator
{
private IntPtr startPtr;
private IntPtr indexPtr;
private bool first_move=true;
internal XmlNodeEnumerator(XmlNodeList list)
{
startPtr=list.DeSerialize();
indexPtr=startPtr;
}
public bool MoveNext()
{
if(indexPtr==IntPtr.Zero)
{
return false; // and prevent a SEGFAULT
}
if(first_move)
{
first_move=false;
return true;
}
indexPtr=Native._xmlNodeGetNextSibling(indexPtr);
if(indexPtr==IntPtr.Zero)
{
return false; // no elements left
}
/* else */
return true;
}
public void Reset()
{
indexPtr=startPtr;
first_move=true;
}
Object IEnumerator.Current
{
get
{
if(indexPtr!=IntPtr.Zero)
{
return XmlNodeFactory.NewNode(indexPtr);
}
else
{
throw new InvalidOperationException(
"Invalid/Bad Enumerator Position");
}
}
}
public XmlNode Current
{
get
{
if(indexPtr!=IntPtr.Zero)
{
return XmlNodeFactory.NewNode(indexPtr);
}
else
{
throw new InvalidOperationException(
"Invalid/Bad Enumerator Position");
}
}
}
}
}
--- NEW FILE ---
/*
* XmlNodeFactory.cs - XmlNodeFactory class -- [TODO]
*
* Copyright (C) 2002 Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using System;
namespace dotgnu.xml
{
public abstract class XmlNodeFactory
{
public static XmlNode NewNode(IntPtr ptr)
{
XmlNode retval;
/*
* TODO: find a way to debug ....
*
* Also fix pnet's switch bug so that this works !
* try #define INCLUDE_TODO and running this
*/
if(ptr==IntPtr.Zero)
{
return null; //should I throw an exception here ?
}
if(XmlNodeCache.IsCached(ptr))
{
return XmlNodeCache.GetCached(ptr);
}
/*
* I wish I could write macros for the following code :(
* identical code .... yuck !
*/
switch(Native._xmlNodeGetElementType(ptr))
{
case XmlElementType.XML_ELEMENT_UNDEF:
throw new Exception("Impossible !");
break;
case XmlElementType.XML_ELEMENT_NODE:
retval=new XmlElement(ptr);
XmlNodeCache.Cache(ptr,retval);
return retval;
break;
case XmlElementType.XML_ATTRIBUTE_NODE:
retval=new XmlAttr(ptr);
XmlNodeCache.Cache(ptr,retval);
return retval;
break;
case XmlElementType.XML_TEXT_NODE:
retval=new XmlText(ptr);
XmlNodeCache.Cache(ptr,retval);
return retval;
break;
case XmlElementType.XML_CDATA_SECTION_NODE:
retval=new XmlCData(ptr);
XmlNodeCache.Cache(ptr,retval);
return retval;
break;
/*TODO*/
case XmlElementType.XML_ENTITY_REF_NODE:
goto default;
/*TODO*/
case XmlElementType.XML_ENTITY_NODE:
goto default;
case XmlElementType.XML_PI_NODE:
retval=new XmlPI(ptr);
XmlNodeCache.Cache(ptr,retval);
return retval;
break;
case XmlElementType.XML_COMMENT_NODE:
retval=new XmlComment(ptr);
XmlNodeCache.Cache(ptr,retval);
return retval;
break;
case XmlElementType.XML_DOCUMENT_NODE:
retval=new XmlDoc(ptr);
XmlNodeCache.Cache(ptr,retval);
return retval;
break;
/*TODO*/
case XmlElementType.XML_DOCUMENT_TYPE_NODE:
retval=new XmlNode(ptr);
XmlNodeCache.Cache(ptr,retval);
return retval;
break;
/*TODO*/
case XmlElementType.XML_DOCUMENT_FRAG_NODE:
retval=new XmlNode(ptr);
XmlNodeCache.Cache(ptr,retval);
return retval;
break;
/*TODO*/
case XmlElementType.XML_NOTATION_NODE:
retval=new XmlNode(ptr);
XmlNodeCache.Cache(ptr,retval);
return retval;
break;
/*TODO*/
case XmlElementType.XML_HTML_DOCUMENT_NODE:
retval=new XmlNode(ptr);
XmlNodeCache.Cache(ptr,retval);
return retval;
break;
/*TODO*/
case XmlElementType.XML_DTD_NODE:
retval=new XmlNode(ptr);
XmlNodeCache.Cache(ptr,retval);
return retval;
break;
/*TODO*/
case XmlElementType.XML_ELEMENT_DECL:
retval=new XmlNode(ptr);
XmlNodeCache.Cache(ptr,retval);
return retval;
break;
/*TODO*/
case XmlElementType.XML_ATTRIBUTE_DECL:
retval=new XmlNode(ptr);
XmlNodeCache.Cache(ptr,retval);
return retval;
break;
/*TODO*/
case XmlElementType.XML_ENTITY_DECL:
retval=new XmlNode(ptr);
XmlNodeCache.Cache(ptr,retval);
return retval;
break;
/*TODO*/
case XmlElementType.XML_NAMESPACE_DECL:
retval=new XmlNode(ptr);
XmlNodeCache.Cache(ptr,retval);
return retval;
break;
/*TODO*/
case XmlElementType.XML_XINCLUDE_START:
retval=new XmlNode(ptr);
XmlNodeCache.Cache(ptr,retval);
return retval;
break;
/*TODO*/
case XmlElementType.XML_XINCLUDE_END:
retval=new XmlNode(ptr);
XmlNodeCache.Cache(ptr,retval);
return retval;
break;
default:
throw new Exception("Unexpected error !");
}
//we never get here !
return null;
}
}
}
--- NEW FILE ---
/*
* XmlNodeList.cs - Node list
*
* Copyright (C) 2002 Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using System.Collections;
namespace dotgnu.xml
{
public class XmlNodeList : IEnumerable
{
private IntPtr startPtr;
public XmlNodeList(IntPtr startPtr)
{
this.startPtr=startPtr;
}
internal IntPtr DeSerialize()
{
return startPtr;
}
public XmlNodeEnumerator GetEnumerator()
{
return new XmlNodeEnumerator(this);
}
IEnumerator IEnumerable.GetEnumerator()
{
return new XmlNodeEnumerator(this);
}
}
}
--- NEW FILE ---
/*
* XmlNs.cs - XmlNs class
*
* Copyright (C) 2002 Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using System;
namespace dotgnu.xml
{
public class XmlNs
{
IntPtr dataPtr=IntPtr.Zero;
internal XmlNs(IntPtr dataPtr)
{
this.dataPtr=dataPtr;
}
public String Href
{
get
{
return Native._xmlNsGetHref(dataPtr);
}
}
public String Prefix
{
get
{
return Native._xmlNsGetPrefix(dataPtr);
}
}
}
}
--- NEW FILE ---
/*
* XmlParser.cs - XmlParser class
*
* Copyright (C) 2002 Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using System;
namespace dotgnu.xml
{
public class XmlParser
{
public static XmlDoc Parse(String filename)
{
IntPtr ptr = Native._xmlParseFile(filename);
if(ptr==IntPtr.Zero)
{
throw new Exception("Could not parse !");
}
XmlDoc doc=(XmlDoc)XmlNodeFactory.NewNode(ptr);
return doc;
}
public static XmlDoc ParseString(String data)
{
IntPtr ptr = Native._xmlParseMemory(data,data.Length);
if(ptr==IntPtr.Zero)
{
throw new Exception("Could not parse !");
}
XmlDoc doc=(XmlDoc)XmlNodeFactory.NewNode(ptr);
return doc;
}
}
}
--- NEW FILE ---
/*
* XmlPI.cs - XmlPI class
*
* Copyright (C) 2002 Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using System;
namespace dotgnu.xml
{
public class XmlPI : XmlNode
{
internal XmlPI(IntPtr dataPtr): base(dataPtr)
{
XmlNodeCache.Cache(dataPtr,this);
}
public XmlPI(String name,String content)
{
dataPtr=Native._xmlNewPI(name,content);
XmlNodeCache.Cache(dataPtr,this);
}
}
}
--- NEW FILE ---
/*
* XmlText.cs - XmlText class
*
* Copyright (C) 2002 Gopal.V
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using System;
namespace dotgnu.xml
{
public class XmlText : XmlNode
{
internal XmlText(IntPtr dataPtr): base(dataPtr);
public XmlText(String content)
{
dataPtr=Native._xmlNewText(content);
XmlNodeCache.Cache(dataPtr,this);
}
public override String Name
{
get
{
return "#TEXT";
}
}
}
}
--- NEW FILE ---
CSCC = cscc
ILASM = ilasm
OUT_FILE=dotgnu.xml.dll
# I had to introduce LIB_FILES to make the order of compilation correct
# and produce a reliable Native.il file ... read pnet's support section
# for bug report on this.
LIB_FILES= Native.cs \
XmlElementType.cs \
XmlNode.cs \
XmlNodeCache.cs \
XmlNodeFactory.cs \
XmlNodeList.cs \
XmlNodeEnumerator.cs \
XmlElement.cs \
XmlAttr.cs \
XmlDoc.cs \
XmlText.cs \
XmlPI.cs \
XmlComment.cs \
XmlCData.cs \
XmlNs.cs \
XmlParser.cs
all : Makefile $(LIB_FILES)
cscc -ftarget-assembly-name=dotgnu.xml -DDEBUG -shared -S $(LIB_FILES)
> err 2>&1
../tools/pinvoke.sh Native.il
ilasm -o $(OUT_FILE) Native.il
clean:
rm -f *.dll *.exe *.*tmp core
rm -f *.il *~
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-libs-commits] CVS: libxmlsharp/dotgnu.xml Native.cs,NONE,1.1 XmlAttr.cs,NONE,1.1 XmlCData.cs,NONE,1.1 XmlComment.cs,NONE,1.1 XmlDoc.cs,NONE,1.1 XmlElement.cs,NONE,1.1 XmlElementType.cs,NONE,1.1 XmlNodeCache.cs,NONE,1.1 XmlNode.cs,NONE,1.1 XmlNodeEnumerator.cs,NONE,1.1 XmlNodeFactory.cs,NONE,1.1 XmlNodeList.cs,NONE,1.1 XmlNs.cs,NONE,1.1 XmlParser.cs,NONE,1.1 XmlPI.cs,NONE,1.1 XmlText.cs,NONE,1.1 Makefile,NONE,1.1,
Gopal.V <address@hidden> <=
- Prev by Date:
[Dotgnu-libs-commits] CVS: libxmlsharp COPYING,NONE,1.1 HACKING,NONE,1.1 INSTALL,NONE,1.1 README,NONE,1.1 Makefile,NONE,1.1 ChangeLog,NONE,1.1 AUTHORS,NONE,1.1 BUGS,NONE,1.1
- Next by Date:
[Dotgnu-libs-commits] CVS: libxmlsharp/samples Makefile,NONE,1.1 builder.cs,NONE,1.1 ns.cs,NONE,1.1 ns.xml,NONE,1.1 struct.cs,NONE,1.1 struct.xml,NONE,1.1 tree.cs,NONE,1.1 tree.xml,NONE,1.1
- Previous by thread:
[Dotgnu-libs-commits] CVS: libxmlsharp COPYING,NONE,1.1 HACKING,NONE,1.1 INSTALL,NONE,1.1 README,NONE,1.1 Makefile,NONE,1.1 ChangeLog,NONE,1.1 AUTHORS,NONE,1.1 BUGS,NONE,1.1
- Next by thread:
[Dotgnu-libs-commits] CVS: libxmlsharp/samples Makefile,NONE,1.1 builder.cs,NONE,1.1 ns.cs,NONE,1.1 ns.xml,NONE,1.1 struct.cs,NONE,1.1 struct.xml,NONE,1.1 tree.cs,NONE,1.1 tree.xml,NONE,1.1
- Index(es):