The NamespaceMap object is used store the namespaces for an element. Each namespace added to this map can be added with a prefix. A prefix is added only if the associated reference has not been added to a parent element. If a parent element has the associated reference, then the parents prefix is the one that will be returned when requested from this map.
Inheritance: System.Collections.Generic.IEnumerable
コード例 #1
0
ファイル: OutputAttribute.cs プロジェクト: restlet/simplexml
 /// <summary>
 /// Constructor for the <c>OutputAttribute</c> object. This
 /// is used to create a simple name value pair attribute holder.
 /// </summary>
 /// <param name="name">
 /// this is the name that is used for the node
 /// </param>
 /// <param name="value">
 /// this is the value used for the node
 /// </param>
 public OutputAttribute(OutputNode source, String name, String value)
 {
     this.scope  = source.Namespaces;
     this.source = source;
     this.value  = value;
     this.name   = name;
 }
コード例 #2
0
ファイル: OutputElement.cs プロジェクト: ngallagher/simplexml
 /// <summary>
 /// Constructor for the <c>OutputElement</c> object. This is
 /// used to create an output element that can create elements for
 /// an XML document. This requires the writer that is used to
 /// generate the actual document and the name of this node.
 /// </summary>
 /// <param name="parent">
 /// this is the parent node to this output node
 /// </param>
 /// <param name="writer">
 /// this is the writer used to generate the file
 /// </param>
 /// <param name="name">
 /// this is the name of the element this represents
 /// </param>
 public OutputElement(OutputNode parent, NodeWriter writer, String name) {
    this.scope = new PrefixResolver(parent);
    this.table = new OutputNodeMap(this);
    this.mode = Mode.INHERIT;
    this.writer = writer;
    this.parent = parent;
    this.name = name;
 }
コード例 #3
0
ファイル: OutputElement.cs プロジェクト: restlet/simplexml
 /// <summary>
 /// Constructor for the <c>OutputElement</c> object. This is
 /// used to create an output element that can create elements for
 /// an XML document. This requires the writer that is used to
 /// generate the actual document and the name of this node.
 /// </summary>
 /// <param name="parent">
 /// this is the parent node to this output node
 /// </param>
 /// <param name="writer">
 /// this is the writer used to generate the file
 /// </param>
 /// <param name="name">
 /// this is the name of the element this represents
 /// </param>
 public OutputElement(OutputNode parent, NodeWriter writer, String name)
 {
     this.scope  = new PrefixResolver(parent);
     this.table  = new OutputNodeMap(this);
     this.mode   = Mode.Inherit;
     this.writer = writer;
     this.parent = parent;
     this.name   = name;
 }
コード例 #4
0
ファイル: NodeWriter.cs プロジェクト: restlet/simplexml
        /// <summary>
        /// This is used to write the namespaces of the specified node to
        /// the output. This will iterate over each namespace entered on
        /// to the node. Once written the node is considered qualified.
        /// </summary>
        /// <param name="node">
        /// this is the node to have is attributes written
        /// </param>
        public void WriteNamespaces(OutputNode node)
        {
            NamespaceMap map = node.getNamespaces();

            for (String name : map)
            {
                String prefix = map.get(name);
                writer.WriteNamespace(name, prefix);
            }
        }
コード例 #5
0
ファイル: NodeWriter.cs プロジェクト: restlet/simplexml
        /// <summary>
        /// This is used to write the namespaces of the specified node to
        /// the output. This will iterate over each namespace entered on
        /// to the node. Once written the node is considered qualified.
        /// </summary>
        /// <param name="node">
        /// This is the node to have is attributes written.
        /// </param>
        public void WriteNamespaces(OutputNode node)
        {
            NamespaceMap map = node.Namespaces;

            foreach (String name in map.References)
            {
                String prefix = map.Get(name);
                writer.WriteNamespace(name, prefix);
            }
        }
コード例 #6
0
ファイル: NamespaceMapTest.cs プロジェクト: restlet/simplexml
        public void TestOutputNode()
        {
            StringWriter out = new StringWriter();
            OutputNode   top  = NodeBuilder.write(out);
            OutputNode   root = top.getChild("root");
            NamespaceMap map  = root.getNamespaces();

            root.setReference("http://www.sun.com/jsp");
            map.put("http://www.w3c.com/xhtml", "xhtml");
            map.put("http://www.sun.com/jsp", "jsp");
            OutputNode child = root.getChild("child");

            child.setAttribute("name.1", "1");
            child.setAttribute("name.2", "2");
            OutputNode attribute = child.getAttributes().get("name.1");

            attribute.setReference("http://www.w3c.com/xhtml");
            OutputNode otherChild = root.getChild("otherChild");

            otherChild.setAttribute("name.a", "a");
            otherChild.setAttribute("name.b", "b");
            map = otherChild.getNamespaces();
            map.put("http://www.w3c.com/xhtml", "ignore");
            OutputNode yetAnotherChild = otherChild.getChild("yetAnotherChild");

            yetAnotherChild.setReference("http://www.w3c.com/xhtml");
            yetAnotherChild.setValue("example text for yet another namespace");
            OutputNode readonlyChild = otherChild.getChild("readonlyChild");

            map = readonlyChild.getNamespaces();
            map.put("http://www.w3c.com/anonymous");
            readonlyChild.setReference("http://www.w3c.com/anonymous");
            OutputNode veryLastChild = readonlyChild.getChild("veryLastChild");

            map = veryLastChild.getNamespaces();
            map.put("");
            OutputNode veryVeryLastChild = veryLastChild.getChild("veryVeryLastChild");

            map = veryVeryLastChild.getNamespaces();
            map.put("");
            veryVeryLastChild.setReference("");
            veryVeryLastChild.setValue("very very last child");
            OutputNode otherVeryVeryLastChild = veryLastChild.getChild("otherVeryVeryLastChild");

            // Problem here with anonymous namespace
            otherVeryVeryLastChild.setReference("http://www.w3c.com/anonymous");
            otherVeryVeryLastChild.setValue("other very very last child");
            OutputNode yetAnotherVeryVeryLastChild = veryLastChild.getChild("yetAnotherVeryVeryLastChild");

            yetAnotherVeryVeryLastChild.setReference("http://www.w3c.com/xhtml");
            yetAnotherVeryVeryLastChild.setValue("yet another very very last child");
            root.commit();
            validate(out.toString());
        }
コード例 #7
0
ファイル: PrefixResolver.cs プロジェクト: restlet/simplexml
        /// <summary>
        /// This method will resolve the prefix or the specified reference
        /// by searching the parent nodes in order. This allows the prefix
        /// that is currently in scope for the reference to be acquired.
        /// </summary>
        /// <param name="reference">
        /// the reference to find a matching prefix for
        /// </param>
        /// <returns>
        /// this will return the prefix that is is scope
        /// </returns>
        public String Resolve(String reference)
        {
            NamespaceMap parent = source.Namespaces;

            if (parent != null)
            {
                String prefix = parent.Get(reference);
                if (!table.ContainsValue(prefix))
                {
                    return(prefix);
                }
            }
            return(null);
        }
コード例 #8
0
 /// <summary>
 /// Constructor for the <c>OutputAttribute</c> object. This
 /// is used to create a simple name value pair attribute holder.
 /// </summary>
 /// <param name="name">
 /// this is the name that is used for the node
 /// </param>
 /// <param name="value">
 /// this is the value used for the node
 /// </param>
 public OutputAttribute(OutputNode source, String name, String value) {
    this.scope = source.Namespaces;
    this.source = source;
    this.value = value;
    this.name = name;
 }