My Xml is not getting correctly validated against the XSD.
I expect the browser to through atleast some kind of generic error messages when i open xml file
My Xml file is below
note.Xml
<?xml version="1.0"?>
<note
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:SchemaLocation="note.xsd">
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
My Xsd file is below
note.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified"><xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
<xs:attribute name="to" type="xs:string" use="required"/>
</xs:complexType>
</xs:element></xs:schema>
Both the note.xml and note.xsd files are in the same folder.
Can somebody guide why i am not getting any error? So Can anyone help me how to validate my xml file with xsd? Thank you,
Three problems:
xsi:schemaLocation attribute value
should be a white-space separate
sequence of namespace URI and schema
document URI, like xsi:schemaLocation="http://www.w3schools.com note.xsd"
You wrote:
I expect the browser to through
atleast some kind of generic error
It's not clear that you are actually
using some validation tool. No
browser validates XML Schema when
you open an XML document.
Your schema targets the
http://www.w3schools.com namespace
URI, but your document is under null
(or empty) namespace URI. This will
end up in validation error, even if
you use the
xsi:noNamespaceSchemaLocation
instead of the xsi:schemaLocation
attribute. Maybe you want to add a
default namespace declaration in
your input source like
xmlns="http://www.w3schools.com"...
Related
I am trying to consume a WSDL, generate source form WSDL and XSDs in gradle using org.apache.cxf.tools.wsdlto.WSDLToJava. It generates classname as it is in XSDs and WSDL, but I want change all the generated class names in similar way. I know I can add binding file to it, but I would need to have entry for every element in the WSDL.
Please help me with a generic for all the properties.
e.g XSD below :
<xs:complexType name="SomeType">
<xs:sequence>
<xs:element name="SomeType2" type="CommonNS:Some2Type"/>
<xs:element name="SomeType3" type="CommonNS:Some3Type" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
The classes generated are :
com.something.SomeType
com.something.Some2Type
com.something.Some3Type
But I want to generate it as :
com.something.Some
com.something.Some2
com.something.Some3
I have a complex XML file that I am trying to import into SQL Server using SQL Server Data Tools. The issue is that there are many nested elements. The SSIS XML Source identifies each collection of children elements as their own table.
For example, I have the following (simplified) XML and XSD:
<?xml version="1.0" encoding="UTF-8"?>
<TrafficReport>
<TrafficElement>
<counts>
<vehicles>
<vehiclesElement>
<vehicleType>car</vehicleType>
<vehicleCount>15</vehicleCount>
</vehiclesElement>
<vehiclesElement>
<vehicleType>truck</vehicleType>
<vehicleCount>5</vehicleCount>
</vehiclesElement>
</vehicles>
<pedestrian>4</pedestrian>
</counts>
<description>
<type>Manual</type>
</description>
</TrafficElement>
</TrafficReport>
XSD:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="Vehicle">
<xs:sequence>
<xs:element name="vehicleType" type="xs:string"/>
<xs:element name="vehicleCount" type="xs:short"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="TrafficCounts">
<xs:sequence>
<xs:element name="vehicles">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="vehiclesElement" type="Vehicle"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="pedestrian" type="xs:short"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="TrafficType">
<xs:sequence>
<xs:element name="type" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Traffic">
<xs:sequence>
<xs:element name="counts" type="TrafficCounts"/>
<xs:element name="description" type="TrafficType"/>
</xs:sequence>
</xs:complexType>
<xs:element name="TrafficReport">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="TrafficElement" type="Traffic"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Using the above XML and XSD, I have the following output tables from SSIS:
My problem with how SSIS creates the tables is that there are so many intermediate tables linking a single child element to the parent element.
My current solution for this is to create an XSL file that transforms the source data into the following XML:
<?xml version="1.0"?>
<TrafficReport>
<TrafficElement>
<vehiclesElement>
<vehicleType>car</vehicleType>
<vehicleCount>15</vehicleCount>
</vehiclesElement>
<vehiclesElement>
<vehicleType>truck</vehicleType>
<vehicleCount>5</vehicleCount>
</vehiclesElement>
<pedestrian>4</pedestrian>
<type>Manual</type>
</TrafficElement>
</TrafficReport>
Here is the XSL file I am using:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="TrafficReport">
<TrafficReport>
<xsl:for-each select="TrafficElement">
<TrafficElement>
<xsl:for-each select="counts/vehicles/vehiclesElement">
<vehiclesElement>
<vehicleType><xsl:value-of select="vehicleType" /></vehicleType>
<vehicleCount><xsl:value-of select="vehicleCount" /></vehicleCount>
</vehiclesElement>
</xsl:for-each>
<pedestrian><xsl:value-of select="counts/pedestrian" /></pedestrian>
<type><xsl:value-of select="description/type" /></type>
</TrafficElement>
</xsl:for-each>
</TrafficReport>
</xsl:template>
</xsl:stylesheet>
With the new XML, SSIS wants to create the following tables which are much easier to work with:
My solution is to pull any children elements to their parent elements, as long as it is a 1:1 relationship. The problem is that creating the XSL file is time consuming (over 750 elements) and I need to do this for multiple files.
Is there an automated way to compress XML to the minimum elements like I am doing manually? (Preferably within SSDT.)
Am I using the XML Source data task incorrectly with the first XML? When trying with the actual data, SSDT identifies over 100 output tables.
Any general suggestions on importing complex XML into SQL Server?
Since you have number of XML files, it's seems you need to use script component to process your XML files, where you can put your logic to extract required data from XML. Also you can LINQ to XML to process your files which is quite faster.
I have a WCF service that expects an object which I'll call StuffContainer. Our client is trying to generate an XML-serialized StuffContainer using JAXB, but it's coming out wrong. They're ending up with type names where they should have property names, so we're not able to deserialize it.
I know nothing about JAXB, but I gather it creates some auto-generated classes based on our XSD, which can be used to build the XML-serialized object.
Here's the relevant snippet of our auto-generated XSD:
<xs:complexType name="StuffContainer">
<xs:sequence>
<xs:element minOccurs="0" name="myStuff" nillable="true" type="tns:ArrayOfStuff"/>
</xs:sequence>
</xs:complexType>
...
<xs:complexType name="ArrayOfStuff">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Stuff" nillable="true" type="tns:Stuff"/>
</xs:sequence>
</xs:complexType>
Our client's code looks something like this:
ObjectFactory objectFactory = new ObjectFactory();
ArrayOfStuff arrayOfStuff = objectFactory.createArrayOfStuff();
JAXBElement<ArrayOfStuff> arrayOfStuffJAXBElement = objectFactory.createArrayOfStuff(arrayOfStuff);
StuffContainer stuffContainer = objectFactory.createStuffContainer();
stuffContainer.setStuff(arrayOfStuffJAXBElement);
Here's the XML they're getting:
<StuffContainer xmlns="..."><ArrayOfStuff>...</ArrayOfStuff></StuffContainer>
But I need it to be:
<StuffContainer xmlns="..."><myStuff>...</myStuff></StuffContainer>
I think this is because the JAXBElement<ArrayOfStuff> that they're getting from the objectFactory has its QName set to "ArrayOfStuff", and this ends up getting used instead of the property name myStuff. But like I said I know nothing about JAXB so I'm not sure what they should be doing differently.
Is there something either that I can change in the XSD, or that I can ask our client to change in their code, so that it generates the correct XML?
There may be multiple methods on the generated ObjectFactory class. The ones corresponding to nested elements have an entire path built into the method name.
I am a bit novice in xml schema. I would be grateful if somebody help me out to understand why my xml is not being validated with the schema:
Here is my Schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/testSchema" xmlns="http://www.example.org/testSchema">
<xs:element name="Employee">
<xs:complexType>
<xs:sequence>
<xs:element name="Name">
<xs:complexType>
<xs:sequence>
<xs:element name="FirstName" />
<xs:element name="LastName" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Here is my test xml:
<?xml version="1.0" encoding="UTF-8"?>
<Employee xmlns="http://www.example.org/testSchema">
<Name>
<FirstName>John</FirstName>
<LastName>Smith</LastName>
</Name>
</Employee>
I am getting following error by Eclipse xml editor/validator:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'Name'. One of '{Name}' is expected.
I could not understand what is wrong with this schema or my xml.
all u have to do is add elementFormDefault="qualified" and u will be fine. to understand this behavior, read "Are You Qualified?" section # http://msdn.microsoft.com/en-us/library/ms950796.aspx
Just add the elementFormDefault="qualified" to the schema attribues.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/testSchema"
elementFormDefault="qualified"
xmlns="http://www.example.org/testSchema">
And your original will work
<?xml version="1.0" encoding="utf-8"?>
<Employee xmlns="http://www.example.org/testSchema">
<Name>
<FirstName>John</FirstName>
<LastName>Smith</LastName>
</Name>
</Employee>
Looks like you're failing to specify how to validate the FirstName and LastName elements; give the element specs for those type="xsd:string" (where xsd needs to be mapped to the XML Schema Datatypes namespace, of course) and all should be well.
But you are better off not nesting those elements so deep. Put them all at the same level and use ref="Name" to link them all together instead; it makes your schema much more flexible and usable.
In SOA I believe that the wsdl does not support recursive data types but I saw some examples where the proxy actually works. Anybody knows more about this?
Recursive type definitions are allowed and even cyclic object graphs are allowed and serializable. However, in order to keep from running out of stack space while serializing and deserializing, you'll need to create a custom behavior overriding the CreateSerializer method and setting the preserveObjectReferences parameter to true when its creating a DataContractSerializer. See James Kovacs' blog for more.
Please define what you mean by recursive. The following is a valid XML Schema for use in a WSDL:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Node" type="NodeType"/>
<xs:complexType name="NodeType">
<xs:sequence>
<xs:element name="Node" type="NodeType"/>
</xs:sequence>
</xs:complexType>
</xs:schema>