Xml Validation Error -> Automatically entered extra character

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sekarm
    New Member
    • Mar 2007
    • 26

    Xml Validation Error -> Automatically entered extra character

    Hi there,
    Hi Everybody, I am facing one problem to validate the xml file. first i load the xml file through XmlDocumentType Class. Before load the Xml file i add the code xmlresolver = null for not validating DTD. Then i get one particular node through getElementBytag name method. After find out the node i have add the attribute fot the node. then i save the xml file in particular path through xmldocumenttype .save() method. After i open the xml file the extra charater that is [] added at end of the DTD. After that i check the xml file through some other check, it throwns a error on special characte [] is added in end of dtd. i dont know when was the special character [] is added in dtd.
    i am using C#.Net 2005. All process are done through XMLDocument class.
    Please give me the solution.

    Thanks In Advance,
    Sekar.M
  • dorinbogdan
    Recognized Expert Contributor
    • Feb 2007
    • 839

    #2
    Please post your code or a part of it that can be tested.
    Thanks,
    Dorin.

    Comment

    • dorinbogdan
      Recognized Expert Contributor
      • Feb 2007
      • 839

      #3
      Oh, and post also the XML file.

      Comment

      • sekarm
        New Member
        • Mar 2007
        • 26

        #4
        Dear Dorin,
        Thank you for your quick reply. please find the xml file and code i attached.

        The Xml File is
        The file name is sample.xml

        Code:
        <?xml version="1.0" encoding="utf-8"?>
        <!DOCTYPE note SYSTEM "note.dtd">
        <ZooRoot>
          <ZooTable Name="Crazy Zoo" Address="32 Turtle Lane" City="Austin" State="TX" Zip="12345">
            <Classification Type="Reptiles" />
            <Classification Type="Birds" />
            <Classification Type="Primates" />
          </ZooTable>
          <ZooTable Name="Chicago Zoo" Address="23 Zebra Ave" City="Chicago" State="IL">
            <Classification Type="Fish" />
            <Classification Type="Mammals" />
            <Classification Type="Primates" />
          </ZooTable>
          <ZooTable Name="Hungry Zoo" Address="45 Lion st" City="Miami" State="FL" Zip="33122">
            <Classification Type="Arachnids" />
            <Classification Type="Rodents" />
          </ZooTable>
        </ZooRoot>
        I have modified the above xml file through below this code,

        Code:
        using System.xml;
        XmlDocument Doc = new XmlDocument();
                    Doc.XmlResolver = null;
                    Doc.Load(@"E:\sample.xml");
                    XmlNodeList RootNode = Doc.GetElementsByTagName("Classification");
                    foreach (XmlNode filesnode in RootNode)
                    {
                        //.ChildNodes[0].RemoveAll();
                        filesnode.RemoveAll();
        
                        XmlNode createnode = Doc.CreateElement("Animal");
                        XmlAttribute attr = Doc.CreateAttribute("AnimalName");
                        attr.Value = "Lion";
                        createnode.Attributes.SetNamedItem(attr);
                        // Creat Attribute For New Node
                        filesnode.AppendChild(createnode);
                    }
                    Doc.Save(@"E:\sample.xml");
        Code:
        <?xml version="1.0" encoding="utf-8"?>
        <!DOCTYPE note SYSTEM "note.dtd"[]> [QUOTE]note it [][/QUOTE]<ZooRoot>
          <ZooTable Name="Crazy Zoo" Address="32 Turtle Lane" City="Austin" State="TX" Zip="12345">
            <Classification>
              <Animal AnimalName="Lion" />
            </Classification>
            <Classification>
              <Animal AnimalName="Lion" />
            </Classification>
            <Classification>
              <Animal AnimalName="Lion" />
            </Classification>
          </ZooTable>
          <ZooTable Name="Chicago Zoo" Address="23 Zebra Ave" City="Chicago" State="IL">
            <Classification>
              <Animal AnimalName="Lion" />
            </Classification>
            <Classification>
              <Animal AnimalName="Lion" />
            </Classification>
            <Classification>
              <Animal AnimalName="Lion" />
            </Classification>
          </ZooTable>
          <ZooTable Name="Hungry Zoo" Address="45 Lion st" City="Miami" State="FL" Zip="33122">
            <Classification>
              <Animal AnimalName="Lion" />
            </Classification>
            <Classification>
              <Animal AnimalName="Lion" />
            </Classification>
          </ZooTable>
        </ZooRoot>
        its correct, but added the extra character in end of DTD that is [], i have highlighted in above code.
        thats the problem, i dont know how is that []bracket added in dtd.
        so give me the solution. if you give the solution its very usefull for me.

        Thanks In advance,
        Sekar.M
        Last edited by sekarm; Apr 11 '07, 01:07 PM. Reason: No Need to Mention it

        Comment

        • dorinbogdan
          Recognized Expert Contributor
          • Feb 2007
          • 839

          #5
          Do you have the note.dtd file too?

          Comment

          • sekarm
            New Member
            • Mar 2007
            • 26

            #6
            Its not necessary Dorin. i have given the code
            Code:
            doc.xmlresolver = null;
            its does not check with any external resources, that is DTD you mention note.dtd.
            you given that above code before document load function, the xmldocument does not care about that note.dtd. Again i tell you need not bother about this. just copy above codes and execute. if you comment the line
            Code:
            doc.xmlresolver=null;
            its thrown the error. so i have use that code..
            just execute the code, then copy the content in one txt file,then give the name
            sample.xml
            and give the location. then execute..
            Please let me know if you have any concern.

            Comment

            • Motoma
              Recognized Expert Specialist
              • Jan 2007
              • 3236

              #7
              What Validator are you using? What is the exact message you are getting?

              Comment

              • Motoma
                Recognized Expert Specialist
                • Jan 2007
                • 3236

                #8
                Take a look at http://www.xml.com/lpt/a/1027.
                Notice the section titled "Valid XML Output: Including DOCTYPE Declarations". If you have your resolver set to null, C# may be inserting the internal DTD subset in order to maintain the validity of your XML Document.

                Comment

                • dorinbogdan
                  Recognized Expert Contributor
                  • Feb 2007
                  • 839

                  #9
                  Originally posted by Motoma
                  Take a look at http://www.xml.com/lpt/a/1027.
                  Notice the section titled "Valid XML Output: Including DOCTYPE Declarations". If you have your resolver set to null, C# may be inserting the internal DTD subset in order to maintain the validity of your XML Document.
                  And the presence of brakets [] will not affect the XML validity.
                  It's working fine as is.

                  Comment

                  • sekarm
                    New Member
                    • Mar 2007
                    • 26

                    #10
                    Thank you all for your kind reply,

                    I have to check my client validation with that xml file. if that bracket is present the validator gives the error message Invalid file. if i manually remove that bracket then i have check the validation its does not thrown error. so its not a correct process for manually removing the bracket. so that i ask that question. i did not know the validation process in client side.

                    ....Sekar

                    Comment

                    Working...