Weird issue while reading XML
im reading xml from this url: https://maven.neoforged.net/releases/net/neoforged/neoform/maven-metadata.xml
like this:
but its printing the data in very weird way:
which is not normal
23 Replies
⌛
This post has been reserved for your question.
Hey @Koblížkáč! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
this is the custom getelement method:
I don't know what XML API you're using. But in XML typical standards, getChildNodes() will also give out the text nodes that make up the whitespace.
You'd be better off querying the right element name rather than everything that's a child.
im using the classic dom api
XmlParser?
Anyway, the DOM API shipped with Java does indeed conform with W3C's general DOM API recommandations, and will indeed give out the whitespace text nodes when calling getChildNodes()
XmlParser is some sort of wrapper class for the whole getting the xml from URL
anyways i find it funny that i works for 1 repository but doesnt for second one
for example: https://maven.minecraftforge.net/de/oceanlabs/mcp/mcp_stable/maven-metadata.xml
Maybe the second one doesn't have whitespace?
these metadata are fetched normally
The URL you just showed doesn't have whitespace and wouldn't have the problem described
I can't vouch for other URLs
how did you find out?
....... I opened it
well i dont really know what you mean by whitespaces
where are them
the files seem identical to me
Whitespace is the blank characters that make it so a text displays like this:
rather than this:
It is performed with newlines, spaces and tabs
doesnt it look the same?
They're both pretty-displayed by your browser. You need to ask your browser to show the actual source
i see now!
so do you think i can safely just purge all the ' ' characters?
While it's not guaranteed in XML, in this case I'd definitely assume you can
However, it would be better style to be able to make do when the whitespace is here
doesnt seem like it would touch the data in any way
does the dom has anything for it or should i use different parser?
Like I said, you should ask for the child you want by its actual name, rather than call getChildNodes()
i mean yeah that would make sense
seems to be working now, big thanks!
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Post Closed
This post has been closed by <@466650807996252162>.