Probleme mit Namespaces

Status
Nicht offen für weitere Antworten.
G

Gichin

Gast
Hallo,

beim erzeugen einer xml-Datei mit jdom 1.1 und Namespaces, ergibt sich folgendes Problem

Code:
<?xml version="1.0" encoding="UTF-8"?>
<shop xmlns="http://www.myCompany.de/XMLSchema/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mycompany.de bl.xsd">
    <computer [b]xmlns=""[/b] name="iBook">
        <Price Price="$500" />
    </computer>
</shop>

wie kann ich dieses verhindern?

xmlns=""

Es sollte erst gar nicht zu sehen sein. Benutzt wird folgender java code:

Code:
 public void createXMLFile() throws IOException {
        Element root = new Element("shop");
        root.setNamespace(DEFAULT_NAMESPACE);
        root.getAttributeValue("ddu", XSI_NAMESPACE);
        root.setAttribute("schemaLocation","http://www.mycompany.de bl.xsd",XSI_NAMESPACE);
       
        Element item1 = new Element("computer");
        item1.setAttribute("name", "iBook");

        Element item2 = new Element("Price");
        item2.setAttribute("Price","$500");

        item1.addContent(item2);
        root.addContent(item1);

        XMLOutputter outputter = new XMLOutputter();
        outputter.output(new Document(root), new FileOutputStream("d:/foo2.xml"));
    }

Vielleicht kann mir jemand sagen was ich dort falsch mache??
 
G

Gichin

Gast
Änderung war sehr einfach, nur das jedem element der Namespace gesetzt werden muss.

Code:
private void processElement(Element element) {
        numElements++;
        List kids = element.getChildren();
        Iterator iterator = kids.iterator();
        while (iterator.hasNext()) {
            Element kid = (Element) iterator.next();
            kid.setNamespace(null);
            processElement(kid);
        }
    }
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
Kirby.exe Probleme mit XML XPATH Select XML & JSON 3
N Probleme bei der Formatierung beim Einfügen und löschen über DOM XML & JSON 7
G Probleme mit Jsoup in .jar File XML & JSON 11
K JAX-WS Bindin-Probleme XML & JSON 1
B Probleme mit RelativeLayout XML & JSON 1
L Jackson JSON: Probleme beim einlesen XML & JSON 1
K XOM Builder Probleme XML & JSON 3
N Jsoup: PHP-Tags bereiten Probleme? XML & JSON 2
M SAX-Parsing Probleme XML & JSON 23
M Probleme mit XPath bei Java XML & JSON 5
hdi Probleme beim Erstellen einer XML XML & JSON 7
F Probleme beim html parsen mit tagsoup XML & JSON 4
M Probleme beim Parsen eines gefilterten XML-Dokuments XML & JSON 6
H JAXB Probleme beim Unmarshalling XML & JSON 3
G Probleme mit XML und JTree XML & JSON 9
klattiator Probleme mit Codierung XML & JSON 3
S Probleme beim erstellen einer Jar XML & JSON 12
T XML und Sonderzeichen, Probleme mit ASP.NET Server XML & JSON 2
D Probleme mit Eclipse Modeling Framework (EMF) XML & JSON 2
S PDF Erzeugung - Probleme mit der XML Datei bei Schema-Infos XML & JSON 2
C SAX Probleme beim lesen XML & JSON 4
F JAXB - Nachträglich hinzugefügter Code macht Probleme XML & JSON 2
D Probleme beim SAX parsing XML & JSON 4
P Probleme mit JDom . addContent(int index,Collection c) XML & JSON 2
F Unmarshall Probleme XML & JSON 5
byte Probleme beim Parsen von XHTML-Datei XML & JSON 4
R Probleme mit Transformer und StreamResult XML & JSON 4
C Probleme mit Include XML & JSON 10
C POI + jXLS Probleme XML & JSON 3
B DOM DTD laden abschalten, Probleme mit Doctypes und PIs XML & JSON 2
S Probleme mit Jdom XML & JSON 3
G probleme mit package XML & JSON 12
M Probleme mit String XML & JSON 3
H Probleme mit xmlrpc und php XML & JSON 13
B Probleme mit Zugriff auf eXist-Datenbank XML & JSON 9
H Neu bei JAVA- Probleme mit der Integration von Xerces XML & JSON 3
P Probleme mit jdom XML & JSON 5
R JAVA und DOM, probleme beim einfügen von elementen ?????? XML & JSON 6
Rakshan Unmarshalling multiple namespaces with jaxb XML & JSON 0
M XML-Datei mit JAXB und 2 Namespaces XML & JSON 0
N Alle namespaces ins Root Element hinauf ziehen XML & JSON 2
N Alle namespaces ins Root Element hinauf ziehen XML & JSON 2
P XPath und Namespaces XML & JSON 3
D XPathAPI.selectSingleNode + Namespaces XML & JSON 4
D XML-file mit Eclipse erstellen + Namespaces XML & JSON 2
X XML/XHTML und Namespaces XML & JSON 2
M XPATH und RSS (Problem namespaces) XML & JSON 7
K xml Datei mit JDOM erzeugen, Problem Namespaces XML & JSON 1

Ähnliche Java Themen

Neue Themen


Oben