INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

XML 'cannot bind to reserved namepace'

XML 'cannot bind to reserved namepace'

(OP)
Hi there, I have a issue with my XML not binding the namespace, please advise, i have taken some words out and replaced with*

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
using System.Xml;
using System.Xml.Schema;
using OAI_Framework.Exceptions;
using System.IO;

public string myXMLDoc(string recVerb, string recIdentifier)
        {           
            //Document
            XmlDocument _xmlDoc = new XmlDocument();
           
           
            XmlSchema schema = new XmlSchema();
            schema.Namespaces.Add("xmlns", "http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/****.xsd");
            _xmlDoc.Schemas.Add(schema);

            XmlDeclaration _dec = _xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
            _xmlDoc.AppendChild(_dec);
            
            //Date and Time
            string recResponsDate = FormatDate(DateTime.Now, "ResponseDate");
            string recDateStamp = FormatDate(DateTime.Now, "ResponseDate");

              Root Element
            
            XmlElement _root = _xmlDoc.CreateElement("OAI-PMH","http://www.openarchives.org/OAI/2.0/***.xsd");

            XmlAttribute _rootAtr_xmlns = _xmlDoc.CreateAttribute("xmlns", "http://www.w3.org/2000/xmlns/");
            XmlAttribute _rootAtr_xmlnsXsi = _xmlDoc.CreateAttribute("xmlns", "xsi", "http://www.w3.org/2000/xmlns/");       
            XmlAttribute _rootAtr_SchemaLoc = _xmlDoc.CreateAttribute("xsi", "schemaLocation", "http://www.w3.org/2001/XMLSchema-instance");
           
            _rootAtr_xmlns.Value = "http://www.openarchives.org/OAI/2.0/";
            _rootAtr_xmlnsXsi.Value = "http://www.w3.org/2001/XMLSchema-instance";
            _rootAtr_SchemaLoc.Value = "http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/***.xsd";
            
            _root.Attributes.Append(_rootAtr_xmlns);
            _root.Attributes.Append(_rootAtr_xmlnsXsi);
            _root.Attributes.Append(_rootAtr_SchemaLoc);

            _xmlDoc.AppendChild(_root);
               

              Response Date
            XmlElement _responseDate = _xmlDoc.CreateElement("responseDate", "http://www.w3.org/2000/xmlns/");
            _responseDate.InnerText = recResponsDate;            
            _root.AppendChild(_responseDate);
             

              Request
            XmlElement _request = _xmlDoc.CreateElement("request", "http://www.openarchives.org/OAI/2.0/***.xsd");

            XmlAttribute _requestAtr_verb = _xmlDoc.CreateAttribute("verb", "http://www.openarchives.org/OAI/2.0/");
            XmlAttribute _requestAtr_ID = _xmlDoc.CreateAttribute("identifier", "http://www.w3.org/2001/XMLSchema-instance");
            XmlAttribute _requestAtr_MetaDatePrefix = _xmlDoc.CreateAttribute("metadataPrefix", "http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/***.xsd");
            
            _requestAtr_verb.Value = recVerb;
            _requestAtr_ID.Value = recIdentifier;
            _requestAtr_MetaDatePrefix.Value = "oai-dc";

            _request.Attributes.Append(_rootAtr_xmlns);
            _request.Attributes.Append(_rootAtr_xmlnsXsi);
            _request.Attributes.Append(_rootAtr_SchemaLoc);

            _request.InnerText = "http://www.kmsystem.ewt.org.za/oai/oai.aspx";

            _root.AppendChild(_request);
             

              Record Type to Pull (verb)
            XmlElement _verbTypeToPull = _xmlDoc.CreateElement(recVerb, "http://www.openarchives.org/OAI/2.0/***.xsd");
            _root.AppendChild(_verbTypeToPull);
                  Record
                XmlElement _record = _xmlDoc.CreateElement("record", "http://www.openarchives.org/OAI/2.0/");                
                _verbTypeToPull.AppendChild(_record);
                      Header
                    XmlElement _header = _xmlDoc.CreateElement("header", "http://www.openarchives.org/OAI/2.0/");
                          identifier
                            XmlElement _header_SUBELEMENT_identifier = _xmlDoc.CreateElement("identifier", "http://www.openarchives.org/OAI/2.0/");
                            _header_SUBELEMENT_identifier.InnerText= "***" + recIdentifier;
                            _header.AppendChild(_header_SUBELEMENT_identifier);
                         
                          datestamp
                            XmlElement _header_SUBELEMENT_datestamp = _xmlDoc.CreateElement("datestamp", "http://www.openarchives.org/OAI/2.0/");
                            _header_SUBELEMENT_datestamp.InnerText = recDateStamp;
                            _header.AppendChild(_header_SUBELEMENT_datestamp);
                         
                    _record.AppendChild(_header);
                     
                      Metadata
                    XmlElement _metadata = _xmlDoc.CreateElement("metadata", "http://www.openarchives.org/OAI/2.0/");                   
                    _record.AppendChild(_metadata);
                          OAI_DC:DC
                        XmlElement _dc = _xmlDoc.CreateElement("oai_dc", "dc", "http://www.openarchives.org/OAI/2.0/oai_dc/");

                        XmlAttribute _dcAtr_oaiDC = _xmlDoc.CreateAttribute("xmlns", "oai_dc", "http://www.w3.org/2000/xmlns/");
                        XmlAttribute _dcAtr_dc = _xmlDoc.CreateAttribute("xmlns", "dc", "http://www.w3.org/2000/xmlns/");
                        XmlAttribute _dcAtr_schemaLocation = _xmlDoc.CreateAttribute("xsi","schemaLocation", "http://www.openarchives.org/OAI/2.0/oai_dc/");

                        _dcAtr_oaiDC.Value = "http://www.openarchives.org/OAI/2.0/oai_dc/";
                        _dcAtr_dc.Value = "http://purl.org/dc/elements/1.1/";
                        _dcAtr_schemaLocation.Value = "http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd";

                        _dc.Attributes.Append(_dcAtr_oaiDC);
                        _dc.Attributes.Append(_dcAtr_dc);
                        _dc.Attributes.Append(_dcAtr_schemaLocation);
                              ALL ELEMENTS(RECORDS) OF OAI_DC
                            int _dsID = Convert.ToInt32(_identifier.Substring(_identifier.LastIndexOf(":")+1));
                            //Get record
                            SqlDataReader reader = SqlHelper.ExecuteReader(_connString, "usp_AOI_GetDataset", _dsID);

                            //Convert to xml
                            if (reader.Read())
                            {
                                  0
                                if (!reader.IsDBNull(0)) //identifier
                                {
                                    XmlNode _emtIdentifier = _xmlDoc.CreateNode(XmlNodeType.Element, "dc", "identifier", "http://www.openarchives.org/OAI/2.0/oai_dc.xsd");
                                    _emtIdentifier.InnerXml = reader["identifier"].ToString();
                                    _dc.AppendChild(_emtIdentifier);
                                }
                                 
                                  1
                                if (!reader.IsDBNull(1)) //title
                                {
                                    XmlNode _emtTitle = _xmlDoc.CreateNode(XmlNodeType.Element, "dc", "title", "http://www.openarchives.org/OAI/2.0/oai_dc.xsd");
                                    _emtTitle.InnerXml = reader["title"].ToString();
                                    _dc.AppendChild(_emtTitle);
                                }
                                 
                                  2
                                if (!reader.IsDBNull(2)) //creator
                                {
                                    XmlNode _emtCreator = _xmlDoc.CreateNode(XmlNodeType.Element, "dc", "creator", "http://www.openarchives.org/OAI/2.0/oai_dc.xsd");
                                    _emtCreator.InnerXml = reader["creator"].ToString();
                                    _dc.AppendChild(_emtCreator);
                                }
                                 
                                  3
                                if (!reader.IsDBNull(3)) //description
                                {
                                    XmlNode _emtDescription = _xmlDoc.CreateNode(XmlNodeType.Element, "dc", "description", "http://www.openarchives.org/OAI/2.0/oai_dc.xsd");
                                    _emtDescription.InnerXml = reader["description"].ToString();
                                    _dc.AppendChild(_emtDescription);
                                }
                                                                  
                                date
                                XmlNode _emtDate = _xmlDoc.CreateNode(XmlNodeType.Element, "dc", "date", "http://www.openarchives.org/OAI/2.0/oai_dc.xsd");
                                _emtDate.InnerXml = recDateStamp;
                                _dc.AppendChild(_emtDate);
                                 
                            }    
            StringWriter strWriter = new StringWriter();
            XmlTextWriter xmlWriter = new XmlTextWriter(strWriter);
            xmlWriter.Formatting = Formatting.Indented;
            xmlWriter.Namespaces = true;
            _xmlDoc.WriteTo(xmlWriter);
            xmlWriter.Flush();
            strWriter.Flush();

            return strWriter.ToString();
        }

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close