I am working on android project and in some portion of task I need to create xml document file. I need to create attribute containing colon like this
<APPLICAD_EXPORT xsi:noNamespaceSchemaLocation="file:///c:/temp/applicad-export.xsd">
I can create xml file sucessfully, but the problem is that I cannot add colon for the attribute APPLICAD_EXPORT.
so far I did like this for getting colon for attribute prefix
XmlSerializer serializer = Xml.newSerializer();
//we set the FileOutputStream as output for the serializer, using UTF-8 encoding
serializer.setOutput(fileos, "UTF-8");
//Write <?xml declaration with encoding (if encoding not null) and standalone flag (if standalone not null)
serializer.startDocument(null, Boolean.valueOf(true));
//set indentation option
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.startTag(null, "APPLICAD_EXPORT");
serializer.attribute(null, "xsi:noNamespaceSchemaLocation", "file:///c:/temp/applicad-export.xsd");
but it shows error saying Specification mandate value for attribute xsi
I guess there may be some way to achieve this but I couldn't figured it out.
The colon is special: your attribute name consists of a namespace prefix (which is a shorthand for the namespace URI, in this case "http://www.w3.org/2001/XMLSchema-instance") and a local name, separated by a colon.
Your call to XmlSerializer.attribute() should specify the namespace URI as the first argument, and the local name ("noNamespaceSchemaLocation") as the second.
You also need to bind the namespace prefix to the URI using XmlSerializer.setPrefix("xsi", "http://www.w3.org/2001/XMLSchema-instance").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With