I'm writing a program which fetches a WSDL and any imported files, then saves them to a single directory. What I want to do as part of this is to flatten the file structure so there's just one directory which contains all the files referenced by the WSDL or referenced by its referenced files. So I need to go into each file and wherever there's an import, I need to strip the path out of the name. Here's an example:
<xsd:import schemaLocation="xsds/Currency.xsd" namespace="urn:example.com:enterprise:schemas:reference:currency">
</xsd:import>
So the import above references the file xsds/Currency.xsd and I want to just extract Currency.xsd from this. I can get the content of this attribute with an XPath expression to match the tag like so:
//*[local-name()='import']/#schemaLocation
However, there are probably other types of tags where a WSDL or it's referenced xsds might import files which this XPath expression won't match. What are the other tags or field names I might need to match on so I don't miss any files?
You might want to use
//#schemaLocation
which would catch all schemaLocation attributes independent of where they occur.
Elements that contain the schemaLocation attributes in the XSD namespace:
import
include
redefine
You should be aware that in the XMLSchema-instance namespace, the qualified schemaLocation attribute will contain space separated pairs where each even-numbered component is a location (the odd-numbered items are namespaces).
Related
I have an existing custom xml file for which I need to add a tag basically append it to the end of root node. But as the xml format will not be changed it can be safely assumed that parsing is not required and only need to add this tag in the end of the file.
XML format:
<links>
...
...
<url type="search">www.google.com</url>
</links>
In the above xml file, I would like to add the tag.
File operation suggests we cannot add in the middle of the file. Can anyone suggest other approaches?
"Safely" is always relative. You can never "safely" assume that you can process XML without parsing unless you are 100% in control of the process that generates the XML, and are confident you will remain so.
And if you are in control of the XML, then I would suggest maintaining it as two files: a content.xml file that holds everything except the root element, and a wrapper.xml file that references content.xml as an external entity:
<!DOCTYPE links [
<!ENTITY e SYSTEM "content.xml">
]>
<links>&e;</links>
and then you can use a normal file append operation on content.xml to add to the content.
I'm writing a library which takes xml files and parses them. To prevent users from feeding inalid xmls into my application i'm using xerces to validate the xml files via an xsd.
However, i only manages to validate against xsd-files. Theoretically an user could just open this file and mess around with it. That's why i would like my xsd to be hardcoded in my library.
Unfortunately i haven't found a way to do this with XercesC++, yet.
That's how it is working right now...
bool XmlParser::validateXml(std::string a_XsdFilename)
{
xercesc::XercesDOMParser domParser;
if (domParser.loadGrammar(a_XsdFilename.c_str(), xercesc::Grammar::SchemaGrammarType) == NULL)
{
throw Exceptions::Parser::XmlSchemaNotReadableException();
}
XercesParserErrorHandler parserErrorHandler;
domParser.setErrorHandler(&parserErrorHandler);
domParser.setValidationScheme(xercesc::XercesDOMParser::Val_Always);
domParser.setDoNamespaces(true);
domParser.setDoSchema(true);
domParser.setValidationSchemaFullChecking(true);
domParser.parse(m_Filename.c_str());
return (domParser.getErrorCount() == 0);
}
std::string m_Filename is a member variable holding the path of the xml i validate.
std::string a_XsdFilename is the path to the xsd i validate against.
XercesParserErrorHandler inherits from xercesc::ErrorHandler and does error handling.
How can i replace std::string a_XsdFilename with something like std::string a_XsdText?
Where std::string a_XsdText contains the schema definition itself instead of a path to a file containing the schema definition.
I'll describe three ways of how to hardcode your XSD in your program:
by loading the XSD from a file path (this is what your example program does right now)
by loading the XSD from a string (this is what you ask for)
by loading the XSD from a precompiled binary
Loading the XSD from a file path
Boris Kolpackov suggests in a blog post that applications should provide the XSD schema files by themselves rather than looking up the schema files through the xsi:schemaLocation or xsi:noNamespaceSchemaLocation attributes found in the XML file.
In the blog post there is a link to load-grammar-dom , an example program (put in the public domain) that makes use of the xercesc::DOMLSParser::loadGrammar function:
user#linux:~$ load-grammar-dom
usage: load-grammar-dom [test.xsd ... ] [test.xml ...]
user#linux:~$
Loading the XSD from a string
If you would like to pass the XSD file contents as a string, you would need to use another overload of
xercesc::DOMLSParser::loadGrammar
where you pass
const DOMLSInput *source
instead of
const char *const systemId
The DOMLSInput could be created with the help of xercesc::MemBufInputSource and xercesc::Wrapper4InputSource like this
xercesc::Wrapper4InputSource source(
new xercesc::MemBufInputSource(
(const XMLByte *) (a_XsdText.c_str()),
a_XsdText.size(),
"A name");
(Adapted somewhat from
https://stackoverflow.com/a/15829424/757777 but untested)
Loading the XSD from a precompiled binary
Included in the software CodeSynthesis XSD the embedded example (that is put in the public domain) demonstrates how to use
xercesc::BinInputStream and
xercesc::XMLGrammarPool::deserializeGrammars
to load a precompiled XSD schema.
See also README.
The example contains the program xsdbin that compiles XSD schema files into a binary file.
user#linux:~$ xsdbin --help
Usage: xsdbin [options] <files>
Options:
--help Print usage information and exit.
--verbose Print progress information.
--output-dir <dir> Write generated files to <dir>.
--hxx-suffix <sfx> Header file suffix instead of '-schema.hxx'.
--cxx-suffix <sfx> Source file suffix instead of '-schema.cxx'.
--array-name <name> Binary data array name.
--disable-multi-import Disable multiple import support.
user#linux:~$
In the makefile the XSD schema file is precompiled by xsdbin and the result ends up inside the example executable.
I have source and target in an informatica powercenter developer. I heed some other header name to be imported in the target file automatically without any manual entry. How can I import customized headers to informatica target.
What have you tried?
You can use a header command in the session configuration for the target, I haven't used it, and couldn't find any documentation on it (i.e. what is possible and how, whether parameters can be used or not, etc.). I did test using (on Windows) an ECHO command to output its text to the header row, but it didn't seem to recognize parameters.
Or you can try to include the header as the first data output row. That means your output will have to be all string types and length restrictions may compound the issue.
Or you can try using two mappings, one that truncates the files and writes the header and one which outputs the data specifying append in the session. You may need two target definitions pointing to the same files. I don't know if the second mapping would attempt to load the existing data (i.e. typecheck), in which case it might throw an error if it didn't match.
Other options may be possible, we don't do much with flat files.
The logic is,
In session command, there is an option called user defined headers. Type echo followed by column name separated by comma delimited
echo A, B, C
I'm writing an app which saves and loads documents both locally and on iCloud. Locally is working fine, but I'm having a problem with iCloud.
The documents are saved as a package - the UIDocument reads and writes an NSFileWrapper which contains an image file, a thumbnail file, and an info plist. When I save the document to iCloud and then look at the files under 'Manage Storage', I see the individual files instead of the packages; and more importantly when I search for files using NSMetadataQuery it returns an NSMetadataItem for each of the individual files instead of the packages. As a result, my app doesn't realise there are any packages to load and iCloud is pretty useless.
I thought that if I set up the document type and exported the UTI correctly that the packages would be treated properly. Was that right? If so, what's the checklist for setting up a document type as a package? I have:
Added a document type
set LSTypeIsPackage to YES (I've tried string YES and bool YES)
set CFBundleTypeExtensions to an array containing one string: the file suffix
set LSHandlerRank to Owner
Exported a UTI with the same identifier
set it to conform to com.apple.package
added a UITypeTagSpecification dictionary, containing an array for the key public.filename-extension, which contains one string: the file suffix
I've also tried adding a matching Imported UTI to match the exported one, but no luck there.
What did I miss?
UPDATE: I notice that the OP in this question is seeing the behaviour I want (even though he doesn't want it) so it must be possible.
Based on this I tried removing the LSItemContentTypes from my plist, and it worked.
how it is possible ,to simply parse html links. For example I receive http response containing http. In which you have links to other files, which need to be downloaded for example jpgs, css files,js files. What is the simplest way to parse all this references.
Use an HTML parser for your platform/language.
There are some recommendations for c++ ones here.
Once you have a parsed document, you will need to look at each src and href in it - you will also need to remember the base tag, if one exists and add logic for external, relative and absolute paths.