I m trying to query a wsdl by using the ?wsdl in the URL. I m able to get the complete WSDL. but the WSDL contains xsd imports with schemalocation like so
"xsd:import namespace="httx://xxxxxxxx/fundTransfer" schemaLocation="../xxx/xxxxxx/FundTransfer.xsd"/>"
How can i query the FundTransfer.xsd from the URL.
I was in the same boat as you earlier and I realized it is not possible at least with Axis 1.4. This was 1+ years back though. It might be different for different soap stacks like CXF etc. It is better to post in the forum of the soap stack vendor you are using as there is no standard defined for this.
Related
Does RapidXML have the capability to validate/parse a XML file with its associated schema, i.e. XSD file? I was under the assumption that an XML parser would have the capability to do both congruently. If not, why is it deemed unnecessary to validate/parse the associated schema? I checked RapidXML's documentation and found no mention of schema or xsd.
I am currently parsing XML files likeso:
rapidxml::file<> xmlFile("BeerLog.xml");
rapidxml::xml_document<> doc;
doc.parse<0>(xmlFile.data());
The following sudo-code might give you a better idea of what I am looking for:
rapidxml::file<> xmlFile("BeerLog.xml", "BeerLog.xsd");
or even:
rapidxml::file<> xmlFile("BeerLog.xml");
rapidxml::file<> xsdFile("BeerLog.xsd");
rapidxml::xml_document<> doc;
doc.parse_with_schema<0>(xsdFile.data(), xmlFile.data());
Your impression is wrong, accessing the content of a XML and validation against a scheme are quite distinct topics- even if the former is useful for the latter. Especially light-wight and fast parsers don't support validation, and a quick glance into the documentation shows this:
W3C Compliance. RapidXml is not a W3C compliant parser, primarily because it ignores DOCTYPE declarations
Given also, that there are quite different scheme languages (XSD, RNG, DTD, ...) even support of one would not mean its the one you would like to.
You will also have to take into account, that there are many XML files, which are just well-formed and do not conform to any scheme - somebody may want to process them nevertheless.
I am using ZEEP to make SOAP requests and it is easy and works great.
The problem is that the endpoint URL (in the WSDL) isn't correct.
I can solve the problem by editing the WSDL directly, but this isn't scalable.
I reviewed the ZEEP documentation about creating service proxies but I don't understand it and am having errors. Here is the part of the WSDL containing the bad URL:
</binding>
<service name="DeviceConfigurationService">
<port name="DeviceConfigurationPort"
binding="xrx:DeviceConfigurationBinding">
<soap:address
location="http://localhost/webservices/office/device_configuration/1"/>
</port>
</service>
the location is what I need to change. I need to change from "localhost" to a LAN IP address. This value may change frequently so I don't want to have to edit the WSDL every time.
Does anyone know how to do this with Zeep?
Any help is greatly appreciated!
I know this question is old, but I just had this same issue as I was accessing a third-party SOAP API with a WSDL that pointed to the wrong endpoint (the third party told me the correct endpoint but hadn't updated their WSDL). The accepted answer did point me in the right direction, but I'd like to offer some additional details that weren't immediately apparent to a fairly novice developer such as myself.
Start by noticing that Zeep's documentation shows that the method zeep.Client.create_service() has two parameters.
binding_name – The QName of the binding
address – The address of the endpoint
Figuring out the binding_name
Option 1 - Read through the WSDL
The binding_name comes from the attribute binding in the WSDL. The issue is that the value of that attribute usually includes a reference to a name elsewhere in the WSDL that you have to manually resolve before using it to create a custom service.
In the case of the excerpt from the OP's WSDL (slightly formatted and ***emphasis added
***)...
<service name="DeviceConfigurationService">
<port name="DeviceConfigurationPort" ***binding="xrx:DeviceConfigurationBinding"***>
<soap:address location="http://localhost/webservices/office/device_configuration/1"/>
</port>
</service>
... the value of binding is "xrx:DeviceConfigurationBinding".
While this is the binding_name used by Zeep, you can't just copy and paste it into the parameter of create_service() because it is partially comprised of xrx - a name defined locally within the WSDL. Zeep automatically resolves the value of this kind of name when it originally parses the WSDL, so when you tell Zeep to point an existing binding to a different endpoint you have to resolve the binding name yourself so Zeep knows which binding you are talking about (that's why #jeffgabhart used {https://path-to-xrx-namespace} in his answer). In the end you should end up with complete binding_name of the format {NAMESPACE}BINDING.
Note that xrx isn't the only possible name. For me, the name was tns and for you it may be something different. Whatever it is, you should be able to find the definition of that name somewhere in the WSDL.
Option 2 - Use Zeep's WSDL parsing utility
Another option is the one suggested by #576i. Running the command python -mzeep WSDL_URL will spit out the information Zeep gathers from the given WSDL. One heading should say "Bindings" followed by a list (possibly of length 1) of binding_name's. From there you can copy the one you need to change the endpoint for.
Option 3 - Get it from the Zeep Client object
This one feels more like a hack, but list(zeep_client.wsdl.port_types) gives a list of all binding names that Zeep found in the WSDL used to create the zeep_client.
Figuring out the address
Lastly, for the sake of completeness, the address is simply the new endpoint you want to use instead of the one defined in the WSDL.
I hope this helps smooth out the learning curve for someone!
client = Client('http://localhost/webservices/office/device_configuration/1?wsdl')
service = client.create_service(
'{http://path-to-xrx-namespace}DeviceConfigurationBinding',
'http://127.0.0.1/webservices/office/device_configuration/1')
service.submit('something')
Is there a quick way to find out all the mandatory field in a xsd file?
I need to quickly see all the mandatory fields in the schema
thanks
Not sure if you're looking to do this through code. If not, Altova XMLSpy, for example, provides an option to "Generate Sample XML File" - with options to generate only mandatory fields.
Otherwise, if you're working with Java, for example, you can use something like the Eclipse XSD project for programmatic access to the XSD. (It even works without Eclipse.) Some additional details at Are there any other frameworks that parse XSD other than XSOM? .
Take a look at this post; instead of exporting all fields, there's also an option to get only the mandatory ones... One significant difference compared with the answer you accepted is in that you can also generate an Excel or CSV file, in addition to the XML file; not to mention that the sample XML approach is deficient by definition... I would pay attention to the way mandatory choices, abstract typed elements or abstract elements with substitution groups play in your case.
Is there an easy way to count the nodes in a HTML file? I also need to count nodes of a certain type such as div etc.
I'd like to do this if possible without having to use an external library like HTMLAgilityPack if possible. Also, the HTML I'm dealing with is not guarenteed to be well formed and valid.
Is there a way to do this from C#?
Thanks.
first of all. are your sure a client-side solution using javascript isn't sufficent to your needs?
because the easiest way to count nodes within an HTML document is using jQuery on the client-side browser.
<script src="http://code.jquery.com/jquery-1.7.min.js"></script>
<script>
$('html').children() // will give you all child elements of the html element
$('body').children() // same for body element
$('body').children('div') // will give you just the direct children elements of 'div' type
$('body').find('div') // will give you all the nested elements of 'div' type
</script>
if you are unfamilier with jQuery then take a look at www.jquery.com
if u still need a C# solution for server-side parsing of the document then then i would recommend to use HTMLAgilityPack (even thou you wish not to). writing your own parser seems to me like a waste of time as you need to consider malformed html/xml and such which can be a pain.
try and use this s-overflow article: What is the best way to parse html in C#?
hope it will satisfy your needs
If you have XHTML you can load it in a XDocument and use XML manipulation API or LINQ to XML to count the particular modes.
If you don't you can try using Regular Expressions. But this one works in small number of interesting tags since you have to define manually an expression for each tag.
With LinqToXml API, you can easily parse and loop through all the nodes of an HTML document. You can find helpful articles related to LinqToXml but all in context of parsing XML documents.
Following is a similar thread from StackOverflow : C# Is there a LINQ to HTML, or some other good .Net HTML manipulation API?
I'm now using spring json view to generate some the outputs. To avoid XSS attacks, we sometimes need to filter the output, escaping javascripts and HTML tags. What is the best way to do it with Spring json view? Do I have to write my own JsonViewWriter or can I simply use sojoJsonWriter and jsonlibJsonWriter with some extra configurations?
Any suggestion will be appreciated!
John
Not sure which Json View you're referring to (there are several), but if it's the "official" one "org.springframework.web.servlet.view.json.MappingJacksonJsonView" you can do it in two ways:
1 - use jackson annotations on your specific data types to customize the serialization
2- write a custom org.codehaus.jackson.map.JsonSerializer which does what you want and plug it in the factory used by your object mapper