public void ReadASingleNodeFromTestDocument()
        {
            Stream gimme = File.Open(TESTFILE_DIR + "SingleNodeSnippet.xml",FileMode.Open);
            XmlReader reader = XmlReader.Create(gimme);
            reader.MoveToContent();

            CommonNamespaces cns = new CommonNamespaces(reader.NameTable, OpenXmlFormat.Transitional);

            XmlNodeInformation nodeInfo = new XmlNodeInformation(reader, cns);

            Assert.AreEqual("Hippopotamus", nodeInfo.NodeName);
            Assert.IsTrue(string.IsNullOrEmpty(nodeInfo.NamespaceURI));
            Assert.AreEqual(2, nodeInfo.AttributeCount);

            reader.Close();
            gimme.Close();
        }
        public void TestPrefixedAttributes()
        {
            Stream gimme = File.Open(TESTFILE_DIR + "Ppt_PrefixedAttributeSnippet.xml", FileMode.Open);
            XmlReader reader = XmlReader.Create(gimme);
            CommonNamespaces cns = new CommonNamespaces(reader.NameTable, OpenXmlFormat.Transitional);

            while (!reader.EOF && reader.Name != "p:sldId")
                reader.Read();
            XmlNodeInformation nodeInfoSlide1 = new XmlNodeInformation(reader, cns);
            Assert.AreEqual("256", nodeInfoSlide1.GetAttributeValue("id"));
            Assert.AreEqual("rId2", nodeInfoSlide1.GetAttributeValue(NamespaceId.r, "id"));

            reader.Read();
            while (!reader.EOF && reader.Name != "p:sldId")  // in case you add extra new lines etc.
                reader.Read();
            XmlNodeInformation nodeInfoSlide2 = new XmlNodeInformation(reader, cns);
            Assert.AreEqual("257", nodeInfoSlide2.GetAttributeValue("id"));
            Assert.AreEqual("rId3", nodeInfoSlide2.GetAttributeValue(NamespaceId.r, "id"));

            while (!reader.EOF && reader.Name != "a:madeupness")  // in case you add extra new lines etc.
                reader.Read();
            XmlNodeInformation nodeInfoBert = new XmlNodeInformation(reader, cns);
            Assert.AreEqual("see", nodeInfoBert.GetAttributeValue("bert"));
            Assert.AreEqual("you", nodeInfoBert.GetAttributeValue(NamespaceId.a, "bert"));
            Assert.AreEqual("next", nodeInfoBert.GetAttributeValue(NamespaceId.p, "bert"));
            Assert.AreEqual("year", nodeInfoBert.GetAttributeValue(NamespaceId.r, "bert"));

            while (!reader.EOF && reader.Name != "r:madeupness")  // in case you add extra new lines etc.
                reader.Read();
            XmlNodeInformation nodeInfoFish = new XmlNodeInformation(reader, cns);
            Assert.AreEqual("haddock", nodeInfoFish.GetAttributeValue("fish"));
            Assert.AreEqual("cod", nodeInfoFish.GetAttributeValue(NamespaceId.a, "fish"));
            Assert.AreEqual("seabass", nodeInfoFish.GetAttributeValue(NamespaceId.p, "fish"));
            Assert.AreEqual("carp", nodeInfoFish.GetAttributeValue(NamespaceId.r, "fish"));

            reader.Close();
            gimme.Close();
        }
Beispiel #3
0
 public XmlNodeInfo(int DepthOfNode, XmlNodeInformation TheNodeInfo)
 {
     depthOfNode = DepthOfNode;
     theNodeInfo = TheNodeInfo;
 }
        public void TestGenerateStyleTriggers()
        {
            List<TriggeringNodeDefinition> existingTriggers = DocxMetadataDefinitions.HiddenDocumentText;

            using (Stream from = File.Open(TESTFILE_DIR + "styles.xml", FileMode.Open))
            {
                StyleSheet sr = new StyleSheet(new CommonNamespaces(OpenXmlFormat.Transitional));
                sr.ConnectToInputStream(from);

                sr.Execute();
                sr.Resolve();

                foreach (TriggeringNodeDefinition tnd in existingTriggers)
                {
                    tnd.NormalizeStrings(sr.CommonNamespaces.NameTable);
                }

                List<TriggeringNodeDefinition> newTriggers = sr.GenerateStyleTriggers(existingTriggers);

                Assert.AreEqual(2, newTriggers.Count);
                TriggeringNodeDefinition tnd1 = newTriggers[0];
                Assert.AreEqual(NamespaceId.w, tnd1.namespaceId);
                Assert.AreEqual("rStyle", tnd1.nodeName);
                Assert.IsTrue(tnd1.attributeFilter.Matches(new AttribDetails("", "val", "", "FooterCharHidden")));


                {
                    MemoryStream ms = new MemoryStream();
                    StreamWriter tw = new StreamWriter(ms);
                    tw.Write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><w:rStyle xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" w:val=\"FooterCharHidden\"/>");
                    tw.Flush();
                    ms.Position = 0;
                    XmlReaderSettings set = new XmlReaderSettings();
                    set.NameTable = sr.CommonNamespaces.NameTable;
                    set.ConformanceLevel = ConformanceLevel.Fragment;
                    XmlReader r = XmlReader.Create(ms, set);
                    r.Read();
                    XmlNodeInformation xni = new XmlNodeInformation(r, sr.CommonNamespaces);
                    TriggerCollection snui = new TriggerCollection(newTriggers);
                    snui.UpdateStringsUsingNametable(set.NameTable);

                    Assert.AreEqual(1, snui.WhatDoesThisNodeTrigger(xni, null).Count);
                    TriggeringNodeDefinition tnd = snui.WhatDoesThisNodeTrigger(xni, null)[0];
                    Assert.AreEqual("rStyle", tnd.nodeName);
                    Assert.IsTrue(tnd.attributeFilter.Matches(new AttribDetails("", NameTableUtils.NormalizeString(sr.CommonNamespaces.NameTable,"val")
                        , "", "FooterCharHidden")));

                    Assert.AreEqual(NamespaceId.w, tnd.namespaceId);

                    Assert.AreEqual(1, tnd.CreateEffects( xni).Count);
                    Effect t = tnd.CreateEffects(xni)[0];
                    Assert.AreEqual(ContentType.HiddenText, t.ContentType);
                    Assert.AreEqual(true, t.BlockPolarity, "expect the polairty of blocking to be +ve as this is a style with hidden on");
                }


                {
                    MemoryStream ms = new MemoryStream();
                    StreamWriter tw = new StreamWriter(ms);
                    tw.Write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><w:rStyle xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" w:val=\"FooterCharNotHidden\"/>");
                    tw.Flush();
                    ms.Position = 0;
                    XmlReaderSettings set = new XmlReaderSettings();
                    set.NameTable = sr.CommonNamespaces.NameTable;
                    set.ConformanceLevel = ConformanceLevel.Fragment;
                    XmlReader r = XmlReader.Create(ms, set);
                    XmlNodeInformation xni = new XmlNodeInformation(r, sr.CommonNamespaces);
                    TriggerCollection snui = new TriggerCollection(newTriggers);

                    Assert.AreEqual(1, snui.WhatDoesThisNodeTrigger(xni, null).Count);
                    TriggeringNodeDefinition tnd = snui.WhatDoesThisNodeTrigger(xni, null)[0];
                    Assert.AreEqual("rStyle", tnd.nodeName);
                    Assert.IsTrue(tnd.attributeFilter.Matches(new AttribDetails("", NameTableUtils.NormalizeString(sr.CommonNamespaces.NameTable, "val")
                        , "", "FooterCharNotHidden")));
                    Assert.AreEqual(NamespaceId.w, tnd.namespaceId);

                    Assert.AreEqual(1, tnd.CreateEffects( xni).Count);
                    Effect t = tnd.CreateEffects( xni)[0];
                    Assert.AreEqual(ContentType.HiddenText, t.ContentType);
                    Assert.AreEqual(false, t.BlockPolarity, "should have -ve polarity because the style specifies not hidden");
                }


                Assert.AreEqual(true, existingTriggers[0].GetDescriptors()[0].DefaultPolarity, "Should not change the default polarity of the base triggerdescriptor for the non-style tag");
            }
        }
Beispiel #5
0
 public WaitingNode(XmlNodeInformation xmlnodeInfo)
 {
     nodeInfo = xmlnodeInfo.CopyWithoutReader();
     remove = false;
 }
        public void TestIntegerToStringLookupEffect()
        {
            Dictionary<string, string> lookup = new Dictionary<string, string>();
            lookup.Add("0", "Nobody We Know");
            lookup.Add("1", "Henry McAlpine");
            lookup.Add("2", "Bicycle Repair Man");

            EffectDescriptor td = new EffectDescriptor();
            td.ContentType = ContentType.Comment;
            td.BlockType = Effect.BlockType.Structure;
            AttributeFilter filter = new NullAttributeFilter();
            td.AddAdditionalInfoDescriptor(new AdditionalInfoDescriptor("Author", "authorID", AdditionalInfoDescriptor.MappingType.StringToStringLookup));

            {
                XmlNodeInformation xni = new XmlNodeInformation(new CommonNamespaces(OpenXmlFormat.Transitional));
                List<AttribDetails> lad = xni.GetAttributes() as List<AttribDetails>;
                lad.Add(new AttribDetails("p", "authorId", @"http://schemas.openxmlformats.org/presentationml/2006/main", "7"));

                GenericEffect ge = td.CreateEffect(2, xni) as GenericEffect;
                List<NodeInfo> geai = ge.GetAdditionalInfo();
                NodeInfo ni = geai[0];
                Assert.AreEqual("Author", ni.name);
                Assert.AreEqual("Unknown", ni.value);
            }

            td.DictStringToStringLookup = lookup;

            {
                XmlNodeInformation xni = new XmlNodeInformation(new CommonNamespaces(OpenXmlFormat.Transitional));
                List<AttribDetails> lad = xni.GetAttributes() as List<AttribDetails>;
                lad.Add(new AttribDetails("p", "authorId", @"http://schemas.openxmlformats.org/presentationml/2006/main", "1"));

                GenericEffect ge = td.CreateEffect(2, xni) as GenericEffect;
                List<NodeInfo> geai = ge.GetAdditionalInfo();
                NodeInfo ni = geai[0];
                Assert.AreEqual("Author", ni.name);
                Assert.AreEqual("Henry McAlpine", ni.value);
            }
            {
                XmlNodeInformation xni = new XmlNodeInformation(new CommonNamespaces(OpenXmlFormat.Transitional));
                List<AttribDetails> lad = xni.GetAttributes() as List<AttribDetails>;
                lad.Add(new AttribDetails("p", "authorId", @"http://schemas.openxmlformats.org/presentationml/2006/main", "2"));

                GenericEffect ge = td.CreateEffect(2, xni) as GenericEffect;
                List<NodeInfo> geai = ge.GetAdditionalInfo();
                NodeInfo ni = geai[0];
                Assert.AreEqual("Author", ni.name);
                Assert.AreEqual("Bicycle Repair Man", ni.value);
            }
            {
                XmlNodeInformation xni = new XmlNodeInformation(new CommonNamespaces(OpenXmlFormat.Transitional));
                List<AttribDetails> lad = xni.GetAttributes() as List<AttribDetails>;
                lad.Add(new AttribDetails("p", "authorId", @"http://schemas.openxmlformats.org/presentationml/2006/main", "7"));

                GenericEffect ge = td.CreateEffect(2, xni) as GenericEffect;
                List<NodeInfo> geai = ge.GetAdditionalInfo();
                NodeInfo ni = geai[0];
                Assert.AreEqual("Author", ni.name);
                Assert.AreEqual("Unknown", ni.value);
            }
        }
 public static Effect Factory(int iDepth, XmlNodeInformation ni, EffectDescriptor ed)
 {
     return new EndNodeRememberingEffect(iDepth);
 }