isekaid_maou
isekaid_maou

Reputation: 283

The markup declarations contained or pointed to by the document type declaration must be well-formed

I have this xml document:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog SYSTEM "plantdtd.dtd">
<catalog>
<title>Flowers of the week</title>
<plant id="A1">
    <name>Aloe vera</name>
    <climate>tropical</climate>
    <height>60-100cm</height>
    <usage>medicinal</usage>
    <image>aloevera.jpg</image>
</plant>
<plant id="A2">
    <name>Orchidaceae</name>
    <height>8-12in</height>
    <usage>medicinal</usage>
    <usage>decoration</usage>
    <image>Orchidaceae.jpg</image>
</plant>
</catalog>

I wrote a DTD like this:

<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE catalog SYSTEM "file:/home/p10398/plantdtd.dtd"
[
<!ELEMENT catalog(title,plant+)>
<!ELEMENT title(#PCDATA)>
<!ELEMENT plant(name,climate,height,usage,image)+>
<!ELEMENT name(#PCDATA)>
<!ELEMENT climate(#PCDATA)>
<!ELEMENT height(#PCDATA)>
<!ELEMENT usage(#PCDATA)>
<!ELEMENT image(#PCDATA)>
]>

Iam getting this error:

Fatal error:                                                                        Public ID: null                                                                  System ID: file:/home/p14524/plantdtd.dtd                                        Line number: 4                                                                   Column number: 3                                                                 Message: The markup declarations contained or pointed to by the document type  declaration must be well-formed.    

Can someone explain whay Iam getting this error? or the correct DTD?

EDITS and UPDATES: Ah! Thanks Daniel. Now the previous error is gone. My new DTD is

<!ELEMENT catalog (title,plant+)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT plant (name,climate,height,usage,image)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT climate (#PCDATA)>
<!ELEMENT height (#PCDATA)>
<!ELEMENT usage (#PCDATA)>
<!ELEMENT image (#PCDATA)>

<!ATTLIST plant id ID #REQUIRED>

Iam getting this new error:

Line number: 18                                                                  Column number: 9                                                                 Message: The content of element type "plant" must match "(name,climate,height,usage,image)".

Upvotes: 4

Views: 24213

Answers (3)

Nayak Kumar Manish
Nayak Kumar Manish

Reputation: 11

I was also getting the same error. But in my case it got resolved like this. Read the whole derscription here

The error i was encountering suggests that there's an issue with the way of my XML payload. In XML, certain characters and structures have specific rules, and any deviation from these rules can result in parsing errors.

In myprovided payload:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE test [<! ENTITY xxe SYSTEM "http://169.254.169.254/" >]>
<stockCheck>
    <productId>
        &xxe;
    </productId>
    <storeId>2</storeId>
</stockCheck>

there's a space between <! and ENTITY, which might be causing the parsing error. Try removing the space to make it <!ENTITY:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE test [<!ENTITY xxe SYSTEM "http://169.254.169.254/" >]>
<stockCheck>
    <productId>
        &xxe;
    </productId>
    <storeId>2</storeId>
</stockCheck>

If the issue persists, consider ensuring that your XML payload adheres to the XML syntax rules. Also, verify that there are no extra spaces, invalid characters, or unclosed tags that might be causing parsing errors.

Upvotes: 0

GoAntonio
GoAntonio

Reputation: 301

"the markup declarations contained or pointed to by the document type declaration must be well formed" error

in my case i was behind a proxy so i guess it was causing issues

<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

so i changed it to https

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >

Upvotes: 2

Daniel Haley
Daniel Haley

Reputation: 52868

You need to remove the DOCTYPE from the DTD. You should also have spaces after the element names in the declarations.

New DTD

<!ELEMENT catalog (title,plant+)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT plant (name,climate,height,usage,image)+>
<!ELEMENT name (#PCDATA)>
<!ELEMENT climate (#PCDATA)>
<!ELEMENT height (#PCDATA)>
<!ELEMENT usage (#PCDATA)>
<!ELEMENT image (#PCDATA)>

Now that the DTD is valid, you will see a few errors when validating your XML.

The first is that you need to declare the id attribute of the plant element. I'd suggest <!ATTLIST plant id ID #REQUIRED>.

The second is that climate is missing from the second plant. I'm not sure if that's an XML error or a DTD error. The element declaration for plant doesn't make a whole lot of sense though because it's those 5 elements in that order one or more times. If you need help with that piece, describe what plant should contain and I can help you write the right declaration.

Upvotes: 3

Related Questions