XML format enforcement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sharon

    XML format enforcement

    I wish to write some kind of XML format enforcer like DTD, XSD or other that
    can do the following:
    (1) Any element and node must have Type attribute that can be read as data
    type by the parser.
    (1) Any element and node may have (optional) four more attributes.

    I XML enforcer should allow any tree structure and any number of nodes in
    any tree.

    Does anyone can tell how it's possible?

    Any example will be most appreciated.


    --
    Thanks
    Sharon
  • robert

    #2
    Re: XML format enforcement

    Sharon,
    It certainly can be done. Visual Studio 2005 can use XSD, but not DTD;
    has methods for attaching external xsd's or you can place the xsd
    inline in the code. Check out the VS documentation. w3.org has
    specifications etc.
    Robert

    Sharon wrote:
    I wish to write some kind of XML format enforcer like DTD, XSD or other that
    can do the following:
    (1) Any element and node must have Type attribute that can be read as data
    type by the parser.
    (1) Any element and node may have (optional) four more attributes.
    >
    I XML enforcer should allow any tree structure and any number of nodes in
    any tree.
    >
    Does anyone can tell how it's possible?
    >
    Any example will be most appreciated.
    >
    >
    --
    Thanks
    Sharon

    Comment

    • Sharon

      #3
      Re: XML format enforcement

      Thanks Robert for your reply.

      I know that XSD can be attached to an XML file, but I don't know how the SAD
      should look like in order to enforce the formatting I have posted.

      Can you post en example showing this?

      P.S.: I'm using VS 2003.


      --
      Thanks
      Sharon

      Comment

      • robert

        #4
        Re: XML format enforcement

        Here is a public dtd issued for xml ucc filings:



        with that, you can get it converted with a dtd to xsd converter.
        Bob

        Sharon wrote:
        Thanks Robert for your reply.
        >
        I know that XSD can be attached to an XML file, but I don't know how the SAD
        should look like in order to enforce the formatting I have posted.
        >
        Can you post en example showing this?
        >
        P.S.: I'm using VS 2003.
        >
        >
        --
        Thanks
        Sharon

        Comment

        • Sharon

          #5
          Re: XML format enforcement

          It seems that ant DTD or XSD defining the node name (parameter name in my
          case), and this not good for me.

          I need to let the user enter any node name he likes, but I do want to force
          him to use my predefined attributes.
          And I can't not find a way to do that.

          Is there ?


          --
          Thanks
          Sharon

          Comment

          • Sharon

            #6
            Re: XML format enforcement

            Ok, I think I found a way to do thanks to Marc Clifton articale on
            CodeProject (http://www.codeproject.com/dotnet/MycroXaml.asp).

            The XML file can be somthing like that:

            <?xml version="1.0" encoding="utf-8"?>
            <System Name="System">
            <Paramaters>
            <Speed type="System.Ii nt32">111</Speed >
            <_xAxis type="System.Si ngle">222</_xAxis>
            <_yAxis type="System.Do uble">333</_yAxis>
            <_ID type="System.In t64">444</_ID>
            <_Name type="System.St ring">String value...</_Name>
            </Paramaters>
            </System>


            And the C# code can be:

            System.IO.Strea mReader sr = new System.IO.Strea mReader("TypesD ef.xml");
            string text = sr.ReadToEnd();
            sr.Close();
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(tex t);
            XmlNode node = doc.FirstChild;
            while( node.NodeType.T oString() != "Element" )
            {
            node = node.NextSiblin g;
            }

            XmlNode paramsNode = doc.SelectSingl eNode("//Paramaters");
            XmlNodeList nodeList = paramsNode.Chil dNodes;
            Hashtable verTypes = new Hashtable(nodeL ist.Count);
            string typeName = "";
            Type type;

            foreach( XmlNode xmlNode in nodeList )
            {
            XmlAttribute attr = xmlNode.Attribu tes["type"];
            typeName = attr.Value;
            if( typeName == "System.Str ing" )
            {
            verTypes[xmlNode.Name] = xmlNode.InnerTe xt;
            }
            else
            {
            type = Type.GetType(ty peName, false);
            object typeIntance = Activator.Creat eInstance(type) ;
            System.Reflecti on.MethodInfo Parse = type.GetMethod( "Parse", new Type
            [] {typeof(String) });
            verTypes[xmlNode.Name] = Parse.Invoke(ty pe, new object[]
            {xmlNode.InnerT ext});
            }
            }

            ------
            Regards
            Sharon

            Comment

            Working...