Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have problem with add schema to xml document. I added a schema to the document and returning ActionResult I get an xml document without a schema. I defined the schema and added individual elements which I later added to the Xml document How can I fix this problem?

What I have tried:

<pre>[HttpGet("ConvertJsonToXML")]
            [Produces("application/xml")]
            public ActionResult ConvertJsonToXML(int? idProjectTlcStairsHistory)
            {
                //Find ID
                var result = _project.FindProjectResult(idProjectTlcStairsHistory);
                // Find name project
                var nameProject = _project.ProjectName(idProjectTlcStairsHistory);
                // Change format on improve format
                var fileName = _project.ReplaceInvalidChars(nameProject);
                JObject o = JObject.Parse(result);
                XmlDocument doc = new XmlDocument();              
                string value = o.ToString();
                doc = JsonConvert.DeserializeXmlNode(value, "StairsCalculationsData");
                XmlSerializerNamespaces nameSpace = new XmlSerializerNamespaces();
                nameSpace.Add("xsd", "http://www.w3.org/2001/XMLSchema");
          
                //Schema
                XmlSchema schema = new XmlSchema();
                schema.ElementFormDefault = XmlSchemaForm.Qualified;
                schema.AttributeFormDefault = XmlSchemaForm.Unqualified;
                schema.Version = "1.0";
                schema.Namespaces = nameSpace;
                XmlSchemaSet schemaSet = new XmlSchemaSet();
                schemaSet.Add(schema);
                XmlSchemaElement element = new XmlSchemaElement();
                element.Name = "SpiralStairs";
                element.SchemaTypeName = new XmlQualifiedName("string", 
                "http://www.w3.org/2001/XMLSchema");
                XmlAttribute attr = doc.CreateAttribute("myns:blah", "http://myns.com");
                attr.Value = "my own attribute";
                element.UnhandledAttributes = new XmlAttribute[] { attr };
                schema.Items.Add(element);
               
                doc.Schemas.Add(schema);
                doc.Schemas.Add(schemaSet);
             
                var file = XMLConvert.AddXmlDeclaration(doc);
                doc.LoadXml(file);
            
                doc.Save(@"C:\Projekty XML\" + fileName + ".xml");
    
                return Ok(doc);      
    
            }





Result - the result he gets without a schematic

<?xml version="1.0" encoding="utf-8"?>
<StairsCalculationsData>
<centralPipeDiameter>150</centralPipeDiameter>
<leftTurn>false</leftTurn>
<rightTurn>true</rightTurn>
<stairsTurn>-1</stairsTurn>
<centralPipeHandrail>false</centralPipeHandrail>
<centralPipeHandrailRadius>120</centralPipeHandrailRadius>
<radius>1000</radius>
<walkingWidth>1185</walkingWidth>
<walkingLineRadius>1000</walkingLineRadius>
<secondWalkingLineRadius>0</secondWalkingLineRadius>
<isStandardRadius>true</isStandardRadius>
<isTlcStandard>true</isTlcStandard>
<maxStepHeight>240</maxStepHeight>
<selectedRadius>1300</selectedRadius>
<selectedStep />
<levels>
<levelNumber>0</levelNumber>
<landing>
<initialDirection>4</initialDirection>
<landingShape>0</landingShape>
<startEdgeHeight>100</startEdgeHeight>
<endEdgeHeight>100</endEdgeHeight>
<startLandingAngle>90</startLandingAngle>
<endLandingAngle>0</endLandingAngle>
<isLandingAngleProperly>true</isLandingAngleProperly>
<landingWidth>1570.7963267948965</landingWidth>
<landingAngle>90</landingAngle>
</landing>
<isLastLevel>false</isLastLevel>
<angleNextLevel>20</angleNextLevel>
<startFlightAngleFromNextLevel>0</startFlightAngleFromNextLevel>
<levelMessages />
<isStepWidthProperly>true</isStepWidthProperly>
<stepDeepInWalkingLine>347.3</stepDeepInWalkingLine>
<heightLevel>2750</heightLevel>
<isStepHeightProperly>false</isStepHeightProperly>
<stepHeight>114.58333333333333</stepHeight>
<rotationRange>1.2777777777777777</rotationRange>
<startFlightAngle>190</startFlightAngle>
<flightRotationRangeAngle>460</flightRotationRangeAngle>
<stepAngle>20</stepAngle>
<isStepsAmountProperly>true</isStepsAmountProperly>
<stepsAmount>24</stepsAmount>
<stepsPerTurn>18</stepsPerTurn>
<isAngleDiffProperly>true</isAngleDiffProperly>
<angleDiff>0</angleDiff>
<isConvinienceProperly>false</isConvinienceProperly>
<convinience>576.47</convinience>
<isFreeSpaceByHeliceProperly>false</isFreeSpaceByHeliceProperly>
<endFreeSpaceByHelice>1440.2</endFreeSpaceByHelice>
<isFreeSpaceProperly>false</isFreeSpaceProperly>
<endFreeSpace>1504.2</endFreeSpace>
<isFlightFreeSpaceProperly>false</isFlightFreeSpaceProperly>
<flightFreeSpace>1847.9</flightFreeSpace>
<isFreeSpaceAboveLandingsProperly>true</isFreeSpaceAboveLandingsProperly>
<freeSpaceAboveLandings>2800</freeSpaceAboveLandings>
</levels>

</StairsCalculationsData>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900